Now, before we start getting things on GitHub and Heroku, we'll first set up a few things inside Atom. We need to set up a .gitignore file, which we'll provide in the root of the project.
The next thing we'll do is configure a few things for Heroku. First up, we have to use the process.env.PORT environment variable. I'll create a constant called port next to the publicPath variable, setting it equal to process.env.PORT or 3000. We'll use it locally:
const publicPath = path.join(__dirname, '../public');
const port = process.env.PORT || 3000;
Now, we can provide port in app.listen, and we can provide it in the following message by changing our regular string to a template string to get Server is up on. I'll inject the port variable value:
app.listen(port, () => {
console.log(`Server is up on ${port}`);
});
Now that we have that in place, the next thing we need to change in order to get our app set up for Heroku is update the package.json file, adding a start script and specifying the version of Node we want to use. Under scripts, I'll add a start script telling Heroku how to start the application. In order to start the app, you have to run the node command. You'll have to go into the server directory, and the file to start it up is server.js:
"scripts": {
"start": "node server/server.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
We're also going to specify engines, which we've done before. engines, as you know, lets you tell Heroku which version of Node to use:
"engines": {
},
This will be important as we are taking advantage of some features only available in the latest versions of Node. Inside engines, I'll provide the exact same key-value pair I used previously, setting node equal to 9.3.0:
"engines": {
"node": "9.3.0"
},
If you're using a different version of Node, you can provide that instead of the version I have added here.