본문 바로가기
  • [성공하는 개발자] - Developer
Node

[Node] 웹서버 만들기

by Sein-JH 2021. 4. 20.
728x90

github.com/web-n/web1_html_internet

 

web-n/web1_html_internet

Contribute to web-n/web1_html_internet development by creating an account on GitHub.

github.com

소스 다운로드

 

var http = require('http');
var fs = require('fs');
var app = http.createServer(function (request, response) {
	var url = request.url;
	if (request.url == '/') {
		url = '/index.html';
	}
	if (request.url == '/favicon.ico') {
		return response.writeHead(404);
	}
	response.writeHead(200);
	response.end(fs.readFileSync(__dirname + url));

});
app.listen(3000);

main.js  코드 작성해 보자

 

node로 실행 해 보면

node main.js

 

http://localhost:3000/  접속해보면 웹페이지가 구동된 것을 볼 수 있다.

 

http://localhost:3000/

 

node 웹서버 구동 완료

'Node' 카테고리의 다른 글

[Node] 파일 읽기 기능  (0) 2021.04.24
[Node] 동적 URL  (0) 2021.04.22
[Node] URL의 이해  (0) 2021.04.21
[Node] Data Type  (0) 2021.04.21
[Node] 다운로드 & 설치  (0) 2021.04.20

댓글