LoginSignup
18
9

More than 5 years have passed since last update.

Herokuで”Web process failed to bind to $PORT”が出力されるとき

Last updated at Posted at 2019-01-21

前提

Node.js, Expressを利用している場合です。

現象

gitbash
git push heroku master
heroku open

このあと画面を開いてもApplication Errorで表示されない。

gitbash
heroku logs

ログを表示するとこのようなログメッセージが出てくる場合。

image.png

heroku_log
Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch

原因

このログの場合はアプリケーションで設定しているポートがherokuが設定するポートと違うためエラーがでている場合があります。
ポート番号を修正してあげれば解決します。

対応

Herokuのサンプルコードからコードをコピー

index.js
const express = require('express')
const path = require('path')
const PORT = process.env.PORT || 5000

express()
  .use(express.static(path.join(__dirname, 'public')))
  .set('views', path.join(__dirname, 'views'))
  .set('view engine', 'ejs')
  .get('/', (req, res) => res.render('pages/index'))
  .listen(PORT, () => console.log(`Listening on ${ PORT }`))

重要なのはPORTの設定が「process.env.PORT || 5000」になっていることです。

18
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
18
9