node.js에서 html불러오기
// 기본 셋팅
PORT = "40000";
HOST = null;
var sys = require('util'),
http = require('http'),
fs = require('fs'),
//sys = require("sys"),
index;
// 콘솔 출력
sys.puts("server starting.");
// html 로드 출력
fs.readFile('./index.html', function (err, data) {
if (err) {
throw err;
}
index = data;
});
http.createServer(function(request, response) {
response.writeHeader(200, {"Content-Type": "text/html"});
response.write(index); // html 로드 출력
response.end(); //close였으나... 다운현상 때문에 end로 변경
}).listen(PORT);
|
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기
댓글 2개
노드제이에스에서는 웹페이지를 저런식으로 가져와서 뿌려줘야 하나요?
단순 HTML 코딩으로는 웹페이지를 열수 없나 보네요.
이거 순수 스크립트로만 짜야하는 형태 인가 봐요?