npm install

Node js 2015. 3. 25. 16:20

노드 js에서 외부 모듈을 설치 시 npm 명령어를 이용합니다 .

npm install 이 안먹혀서 당황을 햇다 그래서 검색 결과 

node js 창이 아니라 cmd 창에서 npm install 모듈명 -g를 해서 먹혔습니다 

 

하지만  var ejs = require('ejs'); 가 안먹히는 것이 었습니다.

그래서 혹시나 해서 -g를 빼고선 했습니다 성공~!!



Posted by 이상욱1
,

node js post

카테고리 없음 2015. 3. 25. 14:57

/**

 * New node file

 */


var http= require('http');

var fs=require('fs');



http.createServer(function (request ,response){

if (request.method =='GET'){

//get

console.log('3');

fs.readFile('htmlpage.html',function(Error, data){

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

response.end(data);

console.log('4');

});

}else if(request.method =='POST'){

//post

request.on('data', function(data){

console.log('1');

console.log('data='+data);

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

response.end('<h1>'+data+'</h1>');

console.log('2'); 

});

}

}).listen(52775 , function(){

console.log('server running at http://127.0.0.1:52775');

});


아래 결과 post 결과값을 화면에 뿌려주었다 






Posted by 이상욱1
,

var http = require('http');

var url= require('url');


http.createServer(function(request , response){

 

console.log('url:'+request.url);

var query = url.parse(request.url ,true).query;

console.log('query'+query);

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

response.end('<h1>'+JSON.stringify(query)+'</h1>');

}).listen(52275 , function(){

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

});


get 값 화면에 출력 한 화면 



Posted by 이상욱1
,