[Node.js] http 모듈로 서버 만들기


[Node.js] http 모듈로 서버 만들기

Node.js 의 기본 모듈인 http 혹은 확장 모듈인 express 를 사용하면 통신의 요청(request)과 응답(response)를 구현할 수 있습니다. 1. 간단한 서버를 만들어보자 // app.js const http = require("http"); http .createServer((req, res) => { res.writeHeader(200, { "Content-Type": "text/html;charset=utf-8" }); res.write("<h1>Node.js로 서버 만들기</h1>"); res.end("<p>http 모듈 공부중입니다.</p>"); }) .listen(8080, () => { console.log("8080포트에서 서버 연결중..."); }); localhost:8080 결과 위에 작성된 코드는 http 모듈을 사용해 서버입니다. 위 코드를 $ node app.js 명령어로 실행하고, localhost:8080 이라는 주소로 웹사이트에 접속...


#http #nodejs #백엔드

원문링크 : [Node.js] http 모듈로 서버 만들기