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
,

아래소스는 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
,

var fs=require('fs');


var http=require('http');


http.createServer(function(request , response){

fs.readFile('beacon.png',function(error  , data){

response.writeHead(200,{'Content-Type':'image/png'})

response.end(data);

});

}).listen(52275,function(){

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

});



음악을 서비스하는경우  content -type 부분의 image/를  'audio/mp3'로 바꿔주면 된다 

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

nodejs jade파일에 데이타 전달 예제  (0) 2015.03.26
npm install  (0) 2015.03.25
node js url로 페이지 이동구분 주기  (0) 2015.03.25
노드 js html 서비스  (0) 2015.03.25
웹서비스 기본 예제  (0) 2015.03.24
Posted by 이상욱1
,

노드 js html 서비스

Node js 2015. 3. 25. 09:51

var fs=require('fs');

console.log('1');

var http=require('http');

console.log('2');


http.createServer(function(request , response){

console.log('3');

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

console.log('4');

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

console.log('5');

console.log('ddd');

response.end(data);

console.log('6');

});

}).listen(52277, function(){

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

});

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

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

웹서비스 기본 예제

Node js 2015. 3. 24. 18:45

require('http').createServer(function (request , response) {

//응답합니다

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

response.end('<h1> hello web server with nose.js</h1>');

}).listen(52275,function(){

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

})


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

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