본문 바로가기

Learn/NodeJS

Node.js 학습 #3 메모장과 cmd로 간단한 작성과 실행

반응형

2020/08/28 - [Learn/NodeJS] - Node.js 학습 #2 설치 Windows

 

Node.js 학습 #2 설치 Windows

2020/08/28 - [Learn/NodeJS] - Node.js 학습 #1 간단히 알아보기 Node.js URL  https://nodejs.org/en/에서 Current 버전과 LTS 버전을 받을 수 있다.  https://github.com/nodejs/LTS/에서 버전 변경 일정을..

javart.tistory.com

 

Node.js

Hello World

콘솔에 Hello World를 출력해볼 것 입니다.

 

1. 메모장 혹은 텍스트 에디터를 열어줍니다.

 

2. console.log('Hellow World'); 를 입력합니다.

메모장

3. 원하는 경로에 "node.basic.js"파일로 저장한다.

.js 확장자에 UTF-8 인코딩

4. cmd를 열고 저장한 경로로 이동한다.

설명을 위해 D:\Test 에 저장

이동 방법은 cmd를 열고, "cd /d 저장경로"를 입력합니다.

 

5. "node node.basic.js"를 입력해 실행한다.

Hello World를 출력했다.


Web Server

 1. 같은 경로에 node.server.js를 생성합니다.

 

 2. 다음 코드를 입력합니다.

//모듈을 불러옵니다.
var http = require('http');

//웹 서버를 생성하고 실행합니다.
http.createServer(function (request, response) {
  response.writeHead(200, {'Content-Type' : 'text/html'});
  response.end('<h1>Hello World...!</h1>');
}).listen(52273, function(){
 console.log("Server running at http://127.0.0.1:52273/');
});

 

3. 같은 방법으로 실행합니다.

cmd로 실행
웹 브라우저 출력

 

반응형