0

I was using scribe js like

app.js

var scribe = require('scribe-js')();
var console=process.console;
app.use(scribe.express.logger());
app.use('/logs', scribe.webPanel());

and in my

module.js

var like = 0;
var error=require('./error');
var console=process.console;  <-- this line
//only works if i comment above line
//else it shows console not defined

var like_dislike = {
    like: function(req, res, next) {
        like++;
        console.log(process.console);
        console.log("Like:" + like + " ClientTime:" + req.query.timestamp);
        res.sendStatus(200)
    }
}
module.exports=like_dislike

Any Idea, atleast where to start looking to resolve this ?

Thanks

EDIT error.js

function error(res, custom_error, actual_error) {
    if (actual_error)
        console.error(actual_error);
    res.status(custom_error.status).send(custom_error.text);
}
module.exports=error;
Aishwat Singh
  • 4,029
  • 2
  • 24
  • 45

1 Answers1

1

The problem is that the express router does not maintain a reference to the console variable (or process, it seems) while passing the request along to the handler. This problem persists even you you try to use the console variable inside an anonymous handler in the same file (not loading a submodule).

The solution is to cache a reference to Scribes console in app.locals and access it via req.app.locals.console. More details at this question: Global Variable in app.js accessible in routes?

I sent you a pull request on github. the updates that I have made are marked with comments in the style of:

/*
 * update explination
 */
Community
  • 1
  • 1
Brady Cartmell
  • 597
  • 2
  • 8