Ubuntu 11.04 で検証。マイナーバージョンアップが頻繁に行われるので注意。
Node.js のインストール
$ wget http://nodejs.org/dist/node-v0.4.10.tar.gz $ sudo aptitude -y install build-essential libssl-dev $ tar xvzf node-v0.4.10.tar.gz $ cd node-v0.4.10/ $ ./configure $ make $ sudo make install $ node -v v0.4.10
Hello World
var sys = require('sys');
var http = require('http');
var server = http.createServer(function (request, response) {
response.writeHead(200, { 'Content-Type': 'text/plain' });
response.write('Hello World!!');
response.end();
}).listen(8124);
sys.log('Server running at http://127.0.0.1:8124/');
$ node helloworld.js 25 Jul 11:45:53 - Server running at http://127.0.0.1:8124/
http://localhost:8124/
にアクセス。
npm のインストール
インストールには root 権限が必要です。
$ curl http://npmjs.org/install.sh | sudo sh
参考
サーバサイドJavaScriptの本命「Node.js」の基礎知識(1/3)- @IT