Node & Express


Node & Express

1. Node.js (1) hello node.js 출력 예제 const http = require("http"); // http 객체 생성 let count = 0; // 노드 서버 객체 생성 (인자: 콜백함수) const server = http.createServer((req, res) => { log(count); res.statusCode = 200; // 요청에 대한 상태코드, 200은 성공을 의미 res.setHeader("Content-Type", "text/plain"); // 요청, 응답에 대한 부가 정보는 header에 설정 res.write("hello\n"); // 응답 // prettier-ignore setTimeout(() => { // 2초 후에 Node.js라는 응답을 주고 http 커넥션을 끝냄 res.end("Node.js"); }, 2000); }); function log(count) { console.log((count += 1)); } se...


#express #expressjs #javascript #js #node #nodejs #백엔드 #서버

원문링크 : Node & Express