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,331
  • 2
  • 26
  • 48

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
  • 607
  • 3
  • 8
  • hey i know that , but scribe attaches its own console – Aishwat Singh Feb 13 '16 at 01:13
  • so ideally without putting `this line` in module.js , i should be able to use console.tag('abc').log('xyz') but i am not , it just logs in scribe without tag – Aishwat Singh Feb 13 '16 at 01:14
  • I see, Scribe is modifying console. After re-reading your question, it seems that your problem is not with console, but with `./error`. What is inside of the `./error` script? – Brady Cartmell Feb 13 '16 at 01:21
  • even if i remove error.js , same issue , and frustrating part is i don't know where to begin – Aishwat Singh Feb 13 '16 at 01:26
  • Then I am misunderstanding what you mean when you say: '<-- this line only works if i comment above line else it shows console not defined'. Does console.log() work if you comment the `...require('./error')` line, or does it work when you comment out the `var console...` line – Brady Cartmell Feb 13 '16 at 01:28
  • Are you working from a branch that hasn't been pushed yet? I don't see anything relevant to scribe and I don't see module.js or error.js – Brady Cartmell Feb 13 '16 at 01:43
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/103348/discussion-between-brady-cartmell-and-aishwat-singh). – Brady Cartmell Feb 13 '16 at 01:51
  • I've updated the answer. I've also sent you a pull request on GitHub with the necessary changes. – Brady Cartmell Feb 13 '16 at 03:55
  • i ended up using process.console() in every line instead of var console=process.console that way it works. But Thanks man , really u went the extra mile to help me out. Thanks a lot :) – Aishwat Singh Feb 13 '16 at 09:09