Step 2

We must make two changes to our repository for Heroku to successfully deploy our application from it.

First, we must add a Procfile to the root of the repository with the following content

web: node ./index.js

A Procfile specifies the commands that are executed by the Heroku app on startup. Read more about it here.

Next, we must update the index.js as follows. Change this line

const port = 5000;

to the following:

const port = process.env.PORT || 5000;

In many environments (e.g. Heroku), and as a convention, you can set the environment variable PORT to tell your web server what port to listen on.

So process.env.PORT || 5000 means: use whatever is in the environment variable PORT as the port number, or 5000 if there's nothing there.

We need this change because Heroku will automatically assign a port to your application. It then stores the port number as a environment variable.

Finally, commit and push your changes. As the new changes get to your GitHub repository, Heroku will build and deploy the application. Give it a minute or two and then visit your your app.

Ours is deployed at https://express-app-1234.herokuapp.com/.