LoginSignup
10
9

More than 5 years have passed since last update.

Node.js + Expressのアプリをherokuにデプロイしたときのメモ

Last updated at Posted at 2013-09-08

herokuにはじめてデプロイした際に手間取ったので忘れないうちにメモ

前提

  • herokuのアカウント作成
  • herokuのtoolbeltをインストール済み
  • デプロイしたいexpressアプリ作成済み

コマンド

作成したherokuアカウントでコマンドラインからログイン

$ heroku login

下記内容が表示

Enter your Heroku credentials.
Email: XXXXXX
Password (typing will be hidden):

鍵作成

本来は上記でid_rsa等鍵が作成されるはずだが、うまくいかなかった為下記で作成

$ ssh-keygen -t rsa -C "メールアドレス"
$ heroku keys:add ~/.ssh/id_rsa.pub

アプリのclone

作成しておいたアプリを下記で落としておく

$ git clone XXXXXXXXXXXXX ${appname}
$ cd ${appname}

gitignoreに設定を追加

heroku側のgitにソースをコミットする際に不要なものを設定

$ vi .gitignore

下記を追記

node_modules
.sass-cache

heroku用にpackage.jsonにengineを追加

"engines": {
"node": "XXX",
"npm": "XXX"
}

herokuで起動するプロセスの起動コマンドを設定ファイルに記述

$ vi Procfile

下記を記述して新規作成

web: node app.js

heroku側にアプリを作成

$ heroku create ${appname}

下記表示

Creating ${appname}… done, stack is cedar
http://${appname}.herokuapp.com/ | git@heroku.com:${appname}.git
Git remote heroku added

アプリのソースコードをherokuにpush

pushと同時にnpmのインストールが実行される
またProcfile内のコマンドが実行される

$ git push heroku master

その他コマンド

ローカルでアプリ起動

$ foreman start

webプロセス確認

$ heroku ps:scale web=1

ログ

$ heroku logs

heroku内でコマンド実行

$ heroku run コマンド

10
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
9