아래소스는 url 로 요청을 각각 구분 주어서 서비스 할 수 있다 



var http= require('http');

var fs=require('fs');

var url=require('url');


http.createServer(function(request,response){

var pathname=url.parse(request.url).pathname;

//페이지 구분 

if(pathname =='/'){

fs.readFile('index.html',function(error , data){

response.writeHead(200 , {'Content-Type': 'text/html'});

response.end(data);

});

}else if(pathname == '/otherpage'){

/*console.log('/other here');*/

fs.readFile('otherpage.html',function(error , data){

response.writeHead(200 , {'Content-Type': 'text/html'});

response.end(data);

});

}

}).listen(52275 ,function(){

console.log('runnig server at http://127.0.0.1:52275');

});


html 파일을 두개 만들어 놓고 조건에 따라서 해당 서비스를 해주는 화면 

결과 값은 아래와 같다 






'Node js' 카테고리의 다른 글

nodejs jade파일에 데이타 전달 예제  (0) 2015.03.26
npm install  (0) 2015.03.25
node js 이미지를 서비스하는경우  (0) 2015.03.25
노드 js html 서비스  (0) 2015.03.25
웹서비스 기본 예제  (0) 2015.03.24
Posted by 이상욱1
,