Skip to content

Instantly share code, notes, and snippets.

@gaboelnuevo
Created July 30, 2017 10:01
Show Gist options
  • Save gaboelnuevo/87586be144721f3b8d561410690915a0 to your computer and use it in GitHub Desktop.
Save gaboelnuevo/87586be144721f3b8d561410690915a0 to your computer and use it in GitHub Desktop.
loopback mongo uri
'use strict';
// serve/datasources.local.js
var mongodbUri = require('mongodb-uri');
var URI = process.env.MONGODB_URI;
var uriObject = URI ? mongodbUri.parse(URI) : null;
var config = {};
if (uriObject && uriObject.hosts.length >= 1) {
config.db = {
name: 'db',
connector: 'mongodb',
host: uriObject.hosts[0].host,
port: uriObject.hosts[0].port,
database: uriObject.database,
username: uriObject.username,
password: uriObject.password,
};
}
module.exports = config;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment