MEAN Part 3 - Create, provision, and deploy to a QA environment using Heroku and MongoLab
8 years ago
- Open the Terminal and create a new heroku project
heroku create meanjs
Create Heroku Dyno
- Create a dyno in Heroku using the following command.
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.
- Login to MongoLab and click on Create New.
- Pick a Cloud Provider and Plan. I usually go with Google Cloud Platform and Single Node (development) - Sandbox.
- Once it is created, click on the database and add a database user. Make sure this user is not read-only.
- Copy the URI generated and format it with the user name and password you created. It should look something like this: mongodb://dbadmin:email@example.com:123456/meanjs
Update NODE_ENV Variables
- Return to the Heroku Dashboard, click on Settings, click Reveal Config Variables, and then the Edit button.
- Add a variable called MONGOLAB_URI and paste the URI what was created above.
- 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://dbadmin:firstname.lastname@example.org:123456/meanjs
- At this point I like to test the database connection by doing the following:
- Return to WebStorm and open up config → env → development.js.
- Under module.exports, replace the db property value with the production database URI you created.
- 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.
- Be sure to revert the connection string back to the original when you’re done testing.