I am trying to run a Node app on a newly created Heroku App from their web. I followed their steps and still I am getting errors when displaying app status.
I followed the Node.js getting started section without the heroku create mand since I already created from the web.
I've also created a Procfile file in the root path with web: npm run start inside.
So when everything is checked I just run these mands and everything looks great until I check the logs or visit the app:
git mit -am "my mit text"
git push heroku master
I see this in the logs:
remote: -----> Compressing...
remote: Done: 18.3M
remote: -----> Launching...
remote: Released v12
remote: / deployed to Heroku
remote:
remote: Verifying deploy... done.
To .git
3656da0..f1eb078 master -> master
So... Any suggestions on what am I doing wrong? Thanks in advance.
I am trying to run a Node app on a newly created Heroku App from their web. I followed their steps and still I am getting errors when displaying app status.
I followed the Node.js getting started section without the heroku create mand since I already created from the web.
I've also created a Procfile file in the root path with web: npm run start inside.
So when everything is checked I just run these mands and everything looks great until I check the logs or visit the app:
git mit -am "my mit text"
git push heroku master
I see this in the logs:
remote: -----> Compressing...
remote: Done: 18.3M
remote: -----> Launching...
remote: Released v12
remote: https://my-app.herokuapp./ deployed to Heroku
remote:
remote: Verifying deploy... done.
To https://git.heroku./my-app.git
3656da0..f1eb078 master -> master
So... Any suggestions on what am I doing wrong? Thanks in advance.
javascript
node.js
git
express
heroku
Share
Improve this question
asked Oct 25, 2018 at 14:53
Martin FernandezMartin Fernandez37811 gold badge55 silver badges1818 bronze badges
Add a ment
|
3 Answers
3
Reset to default
19
You need to provide port for app to listen on in environment variable.
What heroku does is it runs our app on dynamic port.
Try using this:
const PORT = process.env.PORT || 3000;
app.listen(PORT, err => {
if(err) throw err;
console.log("%c Server running", "color: green");
});
Also you shouldn't bind the port to 80, as it is a reserved standard
http port.
Heroku dynos expose a dynamic port for your app to bind to. This value is exposed in the $PORT env var. You must change your code to bind to this port instead.
const port = process.env.PORT || 3000;
app.listen(port, err => {
if(err) throw err;
console.log("%c Server running", "color: green");
});
For modules solution ( "type": "module" in package.json):
const process = require('process');
const port = process.env.PORT || 8080;