Skip to content

Commit

Permalink
Merge pull request #81 from KunalKapadia/develop
Browse files Browse the repository at this point in the history
Print mongoose query logs in dev environment
  • Loading branch information
kunalkapadia committed Oct 12, 2016
2 parents 7b1e091 + d18c54c commit 8cba265
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions config/env/development.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export default {
env: 'development',
MONGOOSE_DEBUG: true,
jwtSecret: '0a6b944d-d2fb-46fc-a85e-0295c986cd9f',
db: 'mongodb://localhost/express-mongoose-es6-rest-api-development',
port: 3000
Expand Down
10 changes: 9 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import Promise from 'bluebird';
import mongoose from 'mongoose';
import util from 'util';
import config from './config/env';
import app from './config/express';

const debug = require('debug')('express-mongoose-es6-rest-api:index');

// plugin bluebird promise in mongoose
mongoose.Promise = Promise;

Expand All @@ -12,7 +15,12 @@ mongoose.connection.on('error', () => {
throw new Error(`unable to connect to database: ${config.db}`);
});

const debug = require('debug')('express-mongoose-es6-rest-api:index');
// print mongoose logs in dev env
if (config.MONGOOSE_DEBUG) {
mongoose.set('debug', (collectionName, method, query, doc) => {
debug(`${collectionName}.${method}`, util.inspect(query, false, 20), doc);
});
}

// listen on port config.port
app.listen(config.port, () => {
Expand Down

0 comments on commit 8cba265

Please sign in to comment.