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
The error happens when Heroku failed to bind the port or hostname at server.listen(port, [host], [backlog], [callback])
.
What Heroku requires is .listen(process.env.PORT)
or .listen(process.env.PORT, '0.0.0.0')
So more generically, to support other environments, use this:
var server_port = process.env.YOUR_PORT || process.env.PORT || 80;
var server_host = process.env.YOUR_HOST || '0.0.0.0';
server.listen(server_port, server_host, function() {
console.log('Listening on port %d', server_port);
});