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
I had the same issue because I didn't define Procfile
. Commit a text file to your app's root directory that is named Procfile
without a file extension. This file tells Heroku which command(s) to run to start your app.
web: node app.js
A fixed number can't be set for port, heroku assigns it dynamically using process.env.PORT
. But you can add them both, like this process.env.PORT || 5000
. Heroku will use the first one, and your localhost will use the second one.
You can even add your call back function. Look at the code below
app.listen(process.env.PORT || 5000, function() {
console.log("Server started.......");
});
I had same issue while using yeoman's angular-fullstack generated project and removing the IP parameter worked for me.
I replaced this code
server.listen(config.port, config.ip, function () {
console.log('Express server listening on %d, in %s mode', config.port, app.get('env'));
});
with
server.listen(config.port, function () {
console.log('Express server listening on %d, in %s mode', config.port, app.get('env'));
});
In my case, I was using example from https://hapijs.com/
To fix the problem I replaced
server.connection({
host: 'localhost',
port: 8000
});
with
server.connection({
port: process.env.PORT || 3000
});
Changing my listening port from 3000 to (process.env.PORT || 5000)
solved the problem.
I had same issue I could resolved issue with replace 'localhost' with IP which is '0.0.0.0'