Hatena::ブログ(Diary)

D-ramu blog RSSフィード

2011-04-08

MacOSXにnode.js環境を構築してみた

| MacOSXにnode.js環境を構築してみたを含むブックマーク MacOSXにnode.js環境を構築してみたのブックマークコメント

f:id:ramtiga:20110408191014p:image


node.jsは、CentOS5.5で試してたけどMacOSにも入れてみた。Machomebrewインストールすると簡単でした。

MacOSX 10.6.7

node.js 0.4.5

まずは、Homebrewが入っていなければ以下のコマンドでインストール

$ ruby -e "$(curl -fsSL https://gist.github.com/raw/323731/install_homebrew.rb)"

・・・
Password:
==> /usr/bin/sudo /usr/bin/chgrp staff /usr/local/. /usr/local/lib
==> Downloading and Installing Homebrew...
==> Installation successful!

確認してみる

$ brew -v
0.8

nodeインストール

$ brew install node

npmインストール

$ curl http://npmjs.org/install.sh | sh

nvmインストール

$ npm install nvm
$ source ~/.bashrc
$ nvm install v0.4.5
$ node -v
v0.4.5

サンプルを試す

node.js公式サイトのサンプルを動かしてみる。

example.jsファイルを作成して以下の内容を記述する

var http = require('http')
http.createServer(function (req,res){
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Hello World!!');
}).listen(8124, "127.0.0.1");
console.log('Server running at http://127.0.0.1:8124/');

実行する

$ node example.js
Server running at http://127.0.0.1:8124/

ブラウザでhttp://127.0.0.1:8124/アクセスすると

f:id:ramtiga:20110408192923p:image

表示されました!


◆参考サイト

node.jsとnpmのインストール - 自分の感受性くらい

トラックバック - http://d.hatena.ne.jp/ramtiga/20110408/p1