다음과 같이 http 모듈을 로드하고, 반환된 HTTP 인스턴스를 http 라는 변수에 저장하기 위해 require 지시문을 사용합니다.
const http = require('http');
생성된 http 인스턴스를 사용하여 http.createServer() 함수를 호출하면, 서버 인스턴스를 생성할 수 있습니다. 서버 인스턴스를 생성한 후, 원하는 포트(3000)를 지정하여 바인딩 합니다.
http://127.0.0.1:3000/ 으로 접속하면 서버가 실행되고 있는 것을 확인하실 수 있습니다.
var http = require("http");
//create a server object:
http
.createServer(function(req, res) {
res.write("Hello World!"); //write a response to the client
res.end(); //end the response
})
.listen(3000); //the server object listens on port 3000
[Node/Tutorial] Blocking / Non blocking 코드 (0) | 2020.11.09 |
---|---|
[Node/Tutorial] npm 으로 패키지 설치하기 (0) | 2020.11.09 |
[Node/Tutorial] Node JS란? (0) | 2020.11.09 |
[Node/Tutorial] Axios 인스턴스로 REST API 사용하기 (0) | 2020.10.22 |
[Node - Tutorial] 구글 계정으로 로그인하기 - (2) - 구글 OAuth 클라이언트 ID 생성하기 (0) | 2020.01.15 |