Files
talk/mongoose.js
T
2016-11-07 11:51:45 -07:00

22 lines
486 B
JavaScript

const mongoose = require('mongoose');
const enabled = require('debug').enabled;
const url = process.env.TALK_MONGO_URL || 'mongodb://localhost';
// Use native promises
mongoose.Promise = global.Promise;
if (enabled('talk:db')) {
mongoose.set('debug', true);
}
try {
mongoose.connect(url, (err) => {
if (err) {throw err;}
console.log('Connected to MongoDB!');
});
} catch (err) {
console.log('Cannot stablish a connection with MongoDB');
}
module.exports = mongoose;