-
Notifications
You must be signed in to change notification settings - Fork 517
Tip: Using with Gulp and Nodemon
Zach Bjornson edited this page Jul 8, 2016
·
1 revision
If you use gulp-nodemon to run your application during development, you can automatically pipe the application's output through the bunyan CLI to format it:
var nodemon = require('gulp-nodemon');
var childProcess = require('child_process');
var path = require('path');
gulp.task('server', function (done) {
nodemon({
script: './server.js', // <-- your application
watch: ['./app'],
stdout: false // <-- important, otherwise output won't get piped properly
})
.on('readable', function () {
// Pass output through bunyan formatter
var bunyan = childProcess.fork(
path.join('.', 'node_modules', 'bunyan', 'bin', 'bunyan'),
['--output', 'simple'], // <-- any of the CLI options that you prefer
{silent: true}
);
bunyan.stdout.pipe(process.stdout);
bunyan.stderr.pipe(process.stderr);
this.stdout.pipe(bunyan.stdin);
this.stderr.pipe(bunyan.stdin);
});
done();
};