Ryusuke Fuda's Tech Blog

Softweare Enginier about Web, iOS, Android.

node.jsインストール

インストール手順
①nave(node.jsバージョン管理)
②node.js
③npm

■naveインストール

$ git clone git://github.com/isaacs/nave.git
$ ./nave/nave.sh install latest

■最新バージョンのnode.jsインストール

$ ./nave/nave.sh use latest

node.jsのバージョン確認

$ node -v
v0.11.0

安定版を使いたい時はlatestをstableにする

■npmインストール

$ sudo chown -R $USER /usr/local/
$ curl http://npmjs.org/install.sh | sh

■サーバーとして動かしてみる

$ node
var http = require('http');
http.createServer(function(req,res){
    res.writeHead(200, {'Content-Type': 'text/plain'});
    res.end('HelloWorld\n');
}).listen(1377, '127.0.0.1');
console.log('Server running at 127.0.0.1:1377');

127.0.0.1:1377 と叩くとHelloWorldと表示される。