본문 바로가기
Programming/환경셋팅

node.js 설치

by Chan_찬 2016. 4. 3.
728x90


node.js 설치

node.js 설치/설정

$ curl -O https://nodejs.org/dist/v4.4.2/node-v4.4.2-linux-x64.tar.xz

$ unxz node-v4.4.2...tar.xz

$ tar -xvf node-v4.4.2...tar

$ echo $PATH

$ vi /etc/profile

export PATH=$PATH:/설치경로/node-v0.10.28/bin

$ source /etc/profile

node.js web 서버

$ vi test.js

var http = require('http');
http.createServer(function(req,res){
     res.writeHead(200,{'Content-Type':'text/plain'});
     res.end('Hello World\n');
}).listen(1337);

http://localhost:1337 접속

mongodb 연동

$ node test.js &

$ vi mongoTest.js

var MongoClient = require('mongodb').MongoClient;
var url = 'mongodb://localhost/test';
function callback(err,db){
console.log('err:'+err+'\ndb:'+db.collection('test'));
db.collection('test').insert({
'ok':1
}, function(e){
console.log(e);
db.close();
});
}
MongoClient.connect(url, callback);

$ node mongoTest.js
error: cannot find module ‘mongodb’

$ npm install mongodb
$ node mongoTest.js

mongo db에서 입력된 값 확인

mongodb> use test
mongodb> db.test.find()


728x90
728x90

'Programming > 환경셋팅' 카테고리의 다른 글

Data Ingestion, Gobblin  (0) 2016.09.27
vim 에서 go syntax highlight  (0) 2016.04.05
Mongo DB (NoSQL) 설치  (0) 2016.03.30
chkconfig 등록 / 설정 / 활용  (0) 2016.03.30
wget 설치방법  (0) 2016.03.29
Buy me a coffeeBuy me a coffee

댓글