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:
- 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
- Push your updates to Heroku:
$ git push heroku master
- 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
- Heroku will automatically generate a key for Mongo Lab. To see what the key is, use the following command:
$ heroku config
- 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:
mongoose.connect("mongodb://localhost/critique-me")
You’d use something like this:
The “MONGODB_URI” refers to the key that’s been generated for MongoLab.mongoose.connect(process.env.MONGODB_URI)
Hopefully this will be useful to anyone else out there who was struggling with their MEAN stack app deployment.