/heroku-mongo-node

Steps to Deploy projects on Heroku with MongoDB and MLab

MIT LicenseMIT

Steps to Deploy Node.js Application to Heroku using MongoDB and MLab

Heroku Setup

  1. First create a Heroku Account

  2. Read Heroku's documentation thoroughly. Check it out here

  3. Setup Heroku CLI as instructed in the above link

  4. Create and deploy the app as instructed here

  5. Push your project folder to Heroku server

Before checking out your app, follow the instructions below to set up mlab

  1. Setup an mlab account

  2. Go to MongoDB Deployments and Create a new deployment

  3. Choose a required plan and select that database

  4. Create a collection and give it a name of your choice. Click on Account and set username and password to give access to database (Not your login credentials for mlab).

  5. In server/index/app configure port:

port: const PORT = process.env.PORT || 5000;
  1. In db.js, MONGODB_URI set up:
const CONNECTION_URI = process.env.MONGODB_URI || 'mongodb://localhost:<your_id>/<name_of_your_db_folder>' 

(MONGODB_URI is available only in production environment, to set it up, follow the next step)

  1. Then in Heroku CLI, setup MongoDB URI by running the command: (ds ID and port might change, please use the URI provided to you)
heroku config:set MONGOLAB_URI='mongodb://<your_username>:<your_password>@ds223653.mlab.com:23653(your mlab collection link given by mlab)/collection_name'
  1. If MONGODB_URI is not supported, then use MONGOLAB_URI