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
For those that are passing both a port and a host, keep in mind that Heroku will not bind to localhost
.
You must pass 0.0.0.0
for host.
Even if you're using the correct port. We had to make this adjustment:
# port (as described above) and host are both wrong
const host = 'localhost';
const port = 3000;
# use alternate localhost and the port Heroku assigns to $PORT
const host = '0.0.0.0';
const port = process.env.PORT || 3000;
Then you can start the server, as usual:
app.listen(port, host, function() {
console.log("Server started.......");
});
You can see more details here: https://help.heroku.com/P1AVPANS/why-is-my-node-js-app-crashing-with-an-r10-error