The trick with deploying your node.js/express app in Heroku

in heroku •  5 years ago  (edited)

If you are working on a simple nodejs/express service and are looking to deploy to Heroku, even though the steps to deploy are really straightforward if you are using the Heroku CLI, when you first deploy your app, you will run into an issue like this.

Screen Shot 2019-10-13 at 12.42.28 PM.png

Usually in your express code, you hard code your port number especially when you're writing a Hello World application. You mayb use a port number like 8084 or 5000. But in Heroku, you can't use the port that you want, Heroku will assign a random port for you. To use the port number that Heroku gives you, you should do the following:

Screen Shot 2019-10-13 at 12.55.48 PM.png

Once you do this, you can deploy your app back on Heroku and it will work!

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!