node.jsでのHello Worldメモ
何となくメモ
環境:Mac 10.6.5
nodeをHomebrewでインストール
wyukawa-no-MacBook-Air:~ wyukawa$ brew install node Warning: It appears you have MacPorts or Fink installed. Software installed with MacPorts and Fink are known to cause problems. If you experience issues try uninstalling these tools. ==> Downloading http://nodejs.org/dist/node-v0.2.5.tar.gz ######################################################################## 100.0% ==> ./configure --prefix=/usr/local/Cellar/node/0.2.5 ==> make install /usr/local/Cellar/node/0.2.5: 69 files, 5.7M, built in 3.9 minutes
npmをHomebrewでインストール
wyukawa-no-MacBook-Air:~ wyukawa$ brew install npm Warning: It appears you have MacPorts or Fink installed. Software installed with MacPorts and Fink are known to cause problems. If you experience issues try uninstalling these tools. ==> Downloading https://github.com/isaacs/npm/tarball/v0.2.11-5 ######################################################################## 100.0% ==> Caveats npm will install binaries to: /usr/local/share/npm/bin You may want to add this to your PATH. npm will install libraries to: /usr/local/lib/node/.npm To manually remove libraries installed by npm, delete this (hidden!) folder. npm will also symlink libraries to: /usr/local/lib/node You will want to add this to your NODE_PATH if you wish to require libraries without a path. ==> Summary /usr/local/Cellar/npm/0.2.11-5: 202 files, 1.7M, built in 2 seconds
パスを設定
wyukawa-no-MacBook-Air:~ wyukawa$ vim .bashrc
export NODE_PATH=/usr/local/lib/node:$PATH export PATH=/usr/local/share/npm/bin:$PATH
本家のサンプルをこぴぺ
example.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/');
起動
wyukawa-no-MacBook-Air:~ wyukawa$ node example.js Server running at http://127.0.0.1:8124/
動作確認
wyukawa-no-MacBook-Air:~ wyukawa$ curl http://127.0.0.1:8124/ Hello World
WebStorm: JetBrains Toolbox subscription
をみるとnode対応するらしい2.0への無償アップグレードもついて2011/01/10まで半額の$34とか。ごくり。
でも@koichikさんが買っちゃダメっていうしなあ。。。というのは冗談としてw
そもそも俺が仕事以外でJSいじるのかっていう根本的な疑問が、、、仕事でもそんないじんないし。半額セールに釣られすぎな気もしてきたw でも体験版くらいためしてみようかな。。。もんさまも絶賛してるし。
こんな記事もあるし。。。
http://journal.mycom.co.jp/column/ide/094/index.html
うーみゅ。