Deploying a MEAN stack app to Heroku

While going through GA’s WDI program, I created a MEAN stack app. I attempted to deploy it when I completed it, however I ran into issues and was too bogged down with classwork to really delve into how to deploy the application.

Today I revisited the app, Critique Me, and was able to successfully deploy it. I figured I’d share the steps here since deployment wasn’t as smooth as deploying Rails applications.

How to Deploy a MEAN stack app to Heroku:

  1. CD into the folder of the application you’d like to deploy. Make sure it’s a Git repo. Then run the following Heroku command in your terminal:
    $ heroku create app-name
  2. Push your updates to Heroku:
    $ git push heroku master
  3. If you visit your live app, you’ll run into an “Application Error.” To resolve this, you need to connect your app to Mongo by using MongoLab:
    $ heroku addons:add mongolab
  4. Heroku will automatically generate a key for Mongo Lab. To see what the key is, use the following command:
    $ heroku config
  5. In the file where you have your MongoDB connection, you’ll need to add the logic for connecting to the production environment. So instead of using the following line:

    You’d use something like this:
    mongoose.connect(process.env.MONGODB_URI)The “MONGODB_URI” refers to the key that’s been generated for MongoLab.

Hopefully this will be useful to anyone else out there who was struggling with their MEAN stack app deployment.

Leave a Reply