mirror of
https://github.com/wassname/talk.git
synced 2026-06-30 04:53:12 +08:00
28 lines
561 B
JavaScript
28 lines
561 B
JavaScript
const mongoose = require('mongoose');
|
|
const debug = require('debug')('talk:db');
|
|
const enabled = require('debug').enabled;
|
|
|
|
//Append '-test' to the db if node_env === 'test'
|
|
let url = process.env.TALK_MONGO_URL || 'mongodb://localhost/coral-talk';
|
|
|
|
if (process.env.NODE_ENV === 'test') {
|
|
url += '-test';
|
|
}
|
|
|
|
// Use native promises
|
|
mongoose.Promise = global.Promise;
|
|
|
|
if (enabled('talk:db')) {
|
|
mongoose.set('debug', true);
|
|
}
|
|
|
|
mongoose.connect(url, (err) => {
|
|
if (err) {
|
|
throw err;
|
|
}
|
|
|
|
debug('connection established');
|
|
});
|
|
|
|
module.exports = mongoose;
|