Skip to content
A Node.js and MongoLab-hosted MongoDB bootstrap for RedHat's OpenShift cloud.
Shell JavaScript
Find file
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
server.js Update environment variables for V2 cartridges Jun 7, 2013

MongoLab OpenShift Quickstart (Node.js and MongoDB)

Step 1. Create an OpenShift account and application

Create an account at and install the rhc command line tool on your development machine. For more info about rhc, see

Once rhc is installed, create a nodejs-0.6 application using the path to this repository as the --from-code argument and by replacing with your desired application name:

> rhc app create <app name> nodejs-0.6 --from-code
> cd <app name>

rhc initializes your application using this repository as a baseline.

Step 2. Create a MongoLab account and database

  1. Sign up for an account at When successful, a database landing page with no databases displays.
  2. Create a database. Be sure to specify a database user name and password. These credentials are not the same as your MongoLab account credentials.
  3. Click on your database. The database landing page provides a mongodb URI connection string of the form:
  1. Copy this value somewhere helpful and replace placeholders with your database user credentials.

Step 3. Commit and deploy the app

When you created your app, the rhc command line client automatically initialized a git repo with a remote link to OpenShift. The code is also already deployed to your app gear.

If you don't make any changes, you can skip this step. However, if you make any modifications (now or later), perform the following to update the code on the gear:

    git add .
    git commit -m "my first commmit"
    git push

Step 4. Configure environment variables on the app gear

The example code uses mongodb://localhost:27017/test when the MONGOLAB_URI environment variable is not available. This is sufficient for testing locally with your own mongodb, but not for production.

Fortunately, the rhc client allows you to configure your environment variable without placing credentials in a repository (see Custom Environment Variables for more information). Use the following commands configure your production URI and restart your app.

    rhc env set MONGOLAB_URI='<db uri>' --app <app name>
    rhc app restart --app <app name>

db uri is the mongodb URI you obtained in Step 2, with your database user credentials added.

Note: Though there are repository-driven methods for configuring this environment variable that meet your requirements, we find that configuring this value outside of the code (and not storing it in a repository) allows for maximum security and flexibility.

Step 5. View the app

Visit your deployed app at:

    http://<app name>-<app namespace>



Something went wrong with that request. Please try again.