January 2018
Beginner
658 pages
13h 10m
English
First up in the server.js file down at the very bottom of the file, we have the port and our app.listen statically coded inside server.js:
app.listen(3000, () => { console.log('Server is up on port 3000');});
We need to make this port dynamic, which means we want to use a variable. We'll be using an environment variable that Heroku is going to set. Heroku will tell your app which port to use because that port will change as you deploy your app, which means that we'll be using that environment variable so we don't have to swap out our code every time we want to deploy.
With environment variables, Heroku can set a variable on the operating system. Your Node app can read that variable and it can use it as the port. ...