Node.js
-
[Node.JS 문법] HTTP모듈Node.js 2020. 7. 22. 00:04
Node J.S에서 HTTP 모듈을 사용하여 서버를 구축해 본다. Hello world 띄우기 const http = require('http'); http.createServer((req, res) => { console.log('서버가 열렸습니다.'); res.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8' }); res.write('Hello World!'); res.end(); }).listen(8080); 1. 동작 원리 설명 1) http모듈 Node의 내장 모듈인 'http'를 require 함수를 통하여 가져 와 const http에 저장한다. 모듈 안의 콜백함수인 createServer() 을 통해 request(요청) 와 res..