node.js 설치 후 정상적인 설치 여부 확인용


샘플 TEST Code


 File Name : nodejs_test_02.js


const http = require('http');


 const hostname = '127.0.0.1';

 const port = 1337;


 http.createServer((req, res) => {

   res.writeHead(200, { 'Content-Type': 'text/plain' });

   res.end('Hello World\n');

 }).listen(port, hostname, () => {

   console.log(`Server running at http://${hostname}:${port}/`);

 });




  // 1. 위 작성된 파일을 실행한다.

    shell> node  nodejs_test_02.js  // 작성된 파일



  // 2. 웹 브라우져를 통해 접속한다.
         크롬이나 익스플로러 등의 웹브라우져 주소창에  
         http://127.0.0.1:1337    <= 주소를 입력한다.


  // 3. 브라우져에 Hello World 가 출력되면 성공