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로 실행 해 보면
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 |
댓글