Last active
January 2, 2016 07:49
-
-
Save simevidas/8272443 to your computer and use it in GitHub Desktop.
Creating the MongoDB URL in a Node web app on AppFog
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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