http(2)
-
[NodeJS] 서버 만들기(HTTP Server) - 2
이번에는 작성한 HTML을 서버를 통해 화면에 출력해 주도록 합니다. index.html 생성합니다. Hello world!!! 그리고 이전 server.js를 수정합니다. const http = require("http");const fs = require("fs");const url = require("url"); http.createServer( (request, response) => { const path = url.parse(request.url, true).pathname;if( path === "/" ) {response.writeHead(200, { "Content-type" : "text/html"} );fs.readFile(__dirname + "/views/index.html", "..
2017.11.28 -
[NodeJS] 서버 만들기(HTTP Server) - 1
HTTP Server를 만들기 위하여 먼서 http 모듈을 로딩한다. const http = require("http"); Server 기본 형태는 다음과 같다. http.createServer( (request, response) => {console.log( "Server Request....!!" );}).listen(8080, () => {console.log( "Server Start. localhost:8080" );}); 작성후 nodejs를 실행하고 브라우저에서 http://localhost:8080을 호출하면 console 창에 Server Start. localhost:8080Server Request....!!이와 같이 출력되는 것을 확인 할 수 있을 것이다. 하지만 브라우저에는 아무..
2017.11.27