简体   繁体   English

抄写JS错误-未定义console.log

[英]scribe js error - console.log not defined

I was using scribe js like 我正在使用scribe js

app.js 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 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 编辑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;

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). 即使您尝试在同一文件的匿名处理程序中使用console变量(未加载子模块),该问题仍然存在。

The solution is to cache a reference to Scribes console in app.locals and access it via req.app.locals.console . 解决方案是app.locals Scribes控制台的引用缓存在app.locals ,并通过req.app.locals.console访问它。 More details at this question: Global Variable in app.js accessible in routes? 有关此问题的更多详细信息: 可在路由中访问app.js中的Global Variable?

I sent you a pull request on github. 我在github上向您发送了请求请求。 the updates that I have made are marked with comments in the style of: 我所做的更新带有以下样式的注释:

/*
 * update explination
 */

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM