I have my first node.js app (runs fine locally) - but I am unable to deploy it via heroku (first time w/ heroku as well). The code is below. SO doesn\'t let me write so much
My problem was that when deploying to heroku I got an error:
Web process failed to bind to $PORT within 60 seconds of launch
when running heroku logs --tail in the terminal. BUT the application would run as expected when I ran the server locally.
I had this in my index.js file (server file)
const PORT = process.env.port || 4000
app.listen(PORT, () => {
console.log(`Server listening on port ${PORT}`)
})
But should have had this
const PORT = process.env.PORT || 4000
app.listen(PORT, () => {
console.log(`Server listening on port ${PORT}`)
})
Use process.env.PORT, not process.env.port, because port is not the same as PORT obviously.
Credit to gprasant.