Skip to content

Instantly share code, notes, and snippets.

@simevidas
Last active January 2, 2016 07:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save simevidas/8272443 to your computer and use it in GitHub Desktop.
Save simevidas/8272443 to your computer and use it in GitHub Desktop.
Creating the MongoDB URL in a Node web app on AppFog
// This is my refactored version of the code available in AppFog’s documentation here:
// https://docs.appfog.com/services/mongodb#node
// The version string is passed to the IIFE as an argument ('mongodb2-2.4.8' in my case)
var mongourl = (function (mongo_version) {
var VCAP = process.env.VCAP_SERVICES;
var obj = VCAP ? JSON.parse(VCAP)[mongo_version][0].credentials : {};
return [
'mongodb://',
(obj.username && obj.password) ? (obj.username + ':' + obj.password + '@') : '',
obj.hostname || 'localhost', ':', obj.port || 27017, '/', obj.db || 'test'
].join('');
}('mongodb2-2.4.8'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment