프로필

프로필 사진
Popomon
Frontend Developer
(2020/12 ~)

    카테고리

    포스트

    [Node/Tutorial] 애플리케이션 생성하기

    2020. 11. 9. 06:35

    꿈가게: To Do List - iOS

    꿈가게: To Do List - Android

    HTTP 모듈 가져오기

    다음과 같이 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