How To Deploy Your Node.js Express App To Heroku

Deploying your Express app can be tricky to say the least. The easiest way that I've found is to use Heroku. Heroku has a real friendly Command Line Interface (CLI) for deploying your Express app.

Follow these steps to deploy your Express App to Heroku:

  1. Install Heroku CLI

Create Heroku Account and install the Heroku Command Line Interface tools. You can find step by step instructions on how to do that here. You'll need Git installed on our computer first but they cover that in the guide here.

2. Confirm Node.js version in package.json

Make sure your version of Node on your machine matches the version you have listed in your package.json file.

3. Create Heroku App Inside Terminal

Make sure you're inside your project directory via your computer terminal and type the following command:

$ heroku create

After Heroku has created your new app, inside your terminal you'll see it gives you a special URL you'll be able to access your app from after you deploy. It will usually be some weird string of words followed by .herokuapp.com.

You can also access this URL from inside your Heroku.com Dashboard.

5. Set Environment Variables

If your application has any environment variables, you'll need to configure those as Heroku environment variables by typing the following commands into Terminal:

$ heroku config:set YOUR_ENVIRONMENT_VARIABLE_NAME="enter variable value here"

6. Deploy to Heroku

Alright we're on the final step! Once you've configured all of your environment variables go and and enter the following command in your terminal:

$ git push heroku master

You should now be able to view your Express App online at your Heroku App URL. If you'd like a custom domain for your Heroku App read this guide.

Troubleshooting

If your app still isn't live, try updating your version of Node.js and NPM and seeing if that fixes the problem.

Show Comments

var.pop( )

Web Development Tips & Tricks