While using debugging techniques during development is helpful (such as the debug
module, console.log
, or the debugger
statement), you should remove the leftovers from the code for production-ready applications.
Fortunately, there's a handy tool just for that, which is called groundskeeper
(https://www.npmjs.org/package/groundskeeper):
$ npm i groundskeeper –g
Let's consider the following sample application:
var debug = require('debug')('myapp:main'); var express = require('express'); var app = express(); app.use(function(req, res, next) { req.session = { user: 'John', email: '[email protected]' }; next(); }); app.get('/', function(req, res, next) { debug('user %s visited /', req.session.user); res.send('ok'); }); app.listen(process.env.PORT || 7777);
The application is really light and contains a single call to the debug
function after requiring it. To remove the two debug lines and write to a new file, run the following command in the terminal:
$ groundskeeper...