https://nodejs.org/download/ よりダウンロード
インストール後シェルから
# node -v v0.12.2
インストールされていることが確認できました。*1
# cat << __EOF__ >> helloworld.js 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!!\n'); response.end(); } ).listen(8124); sys.log('Server running at http://127.0.0.1:8080/'); __EOF__ # node helloworld.js 6 Apr 23:39:07 - Server running at http://127.0.0.1:8080/
ブラウザで、 http://localhost:8080/ へアクセスすると、 予想通り、
Hello World!!
が表示されました。
簡単にWebサーバが構築できましたねー。
とりあえず旧版をインストールして、最新版に入れ替えます。
$ sudo apt-get install -y nodejs npm $ node --version v0.10.29 $ sudo npm cache clean $ sudo npm install n -g /usr/local/bin/n -> /usr/local/lib/node_modules/n/bin/n n@2.1.4 /usr/local/lib/node_modules/n $ sudo n stable .... installed : v7.2.0 $ sudo n 7.2.0 $ node --version v7.2.0 $ sudo n 6.9.1 $ node --version v6.9.1