본문 바로가기
Programming/Node.js

[Node.js]간단한 예제 실행

by _S0_H2_ 2021. 2. 16.
728x90
반응형

1. Visual Studio Code를 이용해서 간단한 코드 작성

 

작업할 폴더 생성 -> hello.js 파일 생성

// Load HTTP module
var http = require("http");

// Create HTTP server and listen on port 8000 for requests
http.createServer(function(request, response) {

   // Set the response HTTP header with HTTP status and Content type
   response.writeHead(200, {'Content-Type': 'text/plain'});

   // Send the response body "Hello World"
   response.end('Hello World\n');
   
}).listen(8000);

// Print URL for accessing server
console.log('Server running at http://127.0.0.1:8000/');

 

2. 소스 실행

cmd -> 작업할 폴더 경로 입력 -> node hello.js(파일명) 입력

 

 

 

 

3.  링크로 접속 http://127.0.0.1:8000/

 

728x90
반응형