(リポジトリの作成は割愛)
1. Herokuにログインする
$heroku login
2. アプリケーションを作成する
$heroku create <アプリケーション名>
HerokuのサイトからGUIでも作成できる。
3. 設定からdb情報を設定する
https://dashboard.heroku.com/apps/<アプリケーション名>/settings
[Reveal Config Var]ボタンから、MongoDBの情報を設定する。
4. Package.JSONを書き換える
トップに下記(自分の環境)を追記する。
"engine" : {
"node":"14.17.0"
},
node --version
で念の為、自分の環境を確認しよう。
5. PORTを書き換える
const PORT = process.env.PORT || 3000;
6. プッシュする
git add -A
git commit -m "Ready for Heroku"
git push origin main && git push heroku main
https://git.heroku.com/<アプリケーション名>.git
エラー['heroku' does not appear to be a git repository]になったら、
git remote add heroku https://git.heroku.com/アプリケーション名.gitとする