ずっと前からherokuがnode.jsをサポート開始したと聞いたが、なかなかやる気が出なくて試してなかった。今日やっと試してみたのでメモ。
OSXでのnode.jsの環境もこの機会でメモしとこうと。
node.jsのインストール
$ wget http://nodejs.org/dist/node-v0.4.12.tar.gz$ tar zxvf node-v0.4.12.tar.gz
$ ./configure
$ make
$ sudo make install
npm(node package manager)インストール
$ wget http://npmjs.org/install.sh
$ sudo ./install.sh
expressインストール
$ sudo npm install -g express
$ sudo npm install -g jade
expressアプリ作成
$ express node-js
$ node app.js
//ここでエラー。express が見つからないと
//app.jsの先頭に以下のパスを追加
require.paths.push('/usr/local/lib/node_modules');
無事に起動されてlocalhost:3000にアクセスできたら、herokuにpush。
通常のrailsのように以下のコマンドでcreate
$ heroku create
git push時に以下のエラーが発生
—–> Heroku receiving push
! Heroku push rejected, no Rails or Rack app detected
以下のコマンドで作成。heroku createとの違いはドメインは ***.heroku.comではなく、***.herokuapp.comになる。
$ heroku create –stack cedar
無事pushできてアクセスしてみると、またエラー
$ heroku logs
で見てみるとportが問題らしい。
app.jsのport設定を修正。
//app.listen(3000);
var port = process.env.PORT || 3000;
app.listen(port, function(){
console.log("Express server listening on port %d in %s mode", app.address().port, app.settings.env);
});
Procfile作成
web: node app.js
もう一度push。
とりあえずできた。
http://node-js.herokuapp.com
Advertisement
Like this:
Be the first to like this post.