node.jsをインストール
環境
Ubuntu 10.10
インストール
% sudo apt-get install nodejs % nodejs -v 0.1.97
テスト
ソース
httpserver.js
var http = require('http'); http.createServer(function (req, res) { res.writeHead(200, {'Content-Type': 'text/plain'}); res.end('Hello World\n'); }).listen(8124, '127.0.0.1'); //console.log('Server running at http://127.0.0.1:8124/');
http://nodejs.org/ から借用。console.logの行をコメントアウトしないと
console.log('Server running at http://127.0.0.1:8124/'); ^ ReferenceError: console is not defined
というエラーが発生する。バージョンが古い。
サーバ起動
% nodejs httpserver.hs
リクエスト送信
% curl http://localhost:8124/ Hello World
感想
パッケージ版はバージョンが古い。現在の最新版は 0.4.0。次はソースから入れてみよう。