アカウント作成
まずは、Herokuの公式サイトでアカウント作成
https://www.heroku.com/
ログイン
// herokuをインストール
$ gem install heroku
$ heroku login
Enter your Heroku credentials.
Email: *******
Password (typing will be hidden):
Authentication successful.
Expressプロジェクト作成
// Expressの雛形ジェネレータをインストール
$ npm install express-generator -g
// Expressプロジェクト作成
$ express プロジェクト名
Herokuにアプリを作成
$ cd プロジェクト
$ git init
$ heroku create
heroku create
でHeroku上にアプリが作成され、カレントディレクトリのremoteリポジトリに作成されたアプリが登録される。
Procfileを作成してデプロイ
以下の内容でプロジェクトルート直下にProcfile
を作成。
web: node ./bin/www
デプロイ
$ git add .
$ git commit -m "initial commit"
$ git push heroku master
ブラウザで確認
$ heroku open
こんな感じでExpressのWelcomeページが表示されれば完了。
ログを確認
$ heroku logs --tail
ローカルでもExpressを起動する
$ gem install foreman
$ foreman start web
これで、localhost:5000
でアクセス可能になる。
参照
Getting Started with Node.js on Heroku
Node.js(Express) 事始め & Heroku へデプロイまでのメモ