First Application with Node.js
Node.js Application 만들기
1단계: 필요한 module import하기
Application에 필요한 module을 불러올 땐
require
명령을 사용HTTP module을 불러오고 반환되는 HTTP instance를 http 변수에 저장함
2단계: Server 생성하기
1단계에서 생성한 http instance를 사용하여
http.createServer()
method 실행listen()
method를 사용하여 port 8081과 bindhttp.createServer()의 매개변수로는 request와 response를 매개변수로 가지고 있는 함수를 넣어줌
main.js
언제나 "Hello World"를 return 하는 port 8081의 web server 생성
3단계: Server test 해보기
서버 실행하기
서버가 성공적으로 실행되면 다음의 text가 출력됨
브라우저에서http://127.0.0.1:8081/ 을 열으면 다음과 같은 결과를 확인 할 수 있음

Last updated
Was this helpful?