MEAN Part 3 - Create, provision, and deploy to a QA environment using Heroku and MongoLab

8 years ago

Create Project

  • Open the Terminal and create a new heroku project
heroku create meanjs

Create Heroku Dyno

  • Create a dyno in Heroku using the following command.[1]
heroku ps:scale web=1

Create MongoDB Database

  • Create a MongoDB database using the Heroku Add-On feature or directly through MongoLab or MongoHQ. All of these options are free, but using the Heroku Add-On feature requires entering a credit card number. The following instructions use MongoLab and assumed you already have an account.
  1. Login to MongoLab and click on Create New.
  2. Pick a Cloud Provider and Plan. I usually go with Google Cloud Platform and Single Node (development) - Sandbox.
  3. Once it is created, click on the database and add a database user. Make sure this user is not read-only.
  4. Copy the URI generated and format it with the user name and password you created. It should look something like this: mongodb://

Update NODE_ENV Variables

  • Return to the Heroku Dashboard, click on Settings, click Reveal Config Variables, and then the Edit button.
  1. Add a variable called MONGOLAB_URI and paste the URI what was created above.
  2. Add a variable called NODE_ENV and enter production.

These can optionally be created using the Heroku toolbelt (CLI) by running the following commands:

heroku config:set NODE_ENV=production
heroku config:set MONGOLAB_URI=mongodb://


  • At this point I like to test the database connection by doing the following:
  1. Return to WebStorm and open up config → env → development.js.
  2. Under module.exports, replace the db property value with the production database URI you created.
  3. At this point you should be able to refresh the browser, sign up with a different account, and add an article. Like the steps mentioned above, I like to use the string “prod”, so I can easily differentiate.
  4. Be sure to revert the connection string back to the original when you’re done testing.
Discuss on Twitter