Is it possible to get the current request that is being served by node.js?
Posted
by
user420504
on Stack Overflow
See other posts from Stack Overflow
or by user420504
Published on 2012-09-25T03:35:02Z
Indexed on
2012/09/25
3:37 UTC
Read the original article
Hit count: 133
I am using express.js. I have a need to be able to log certain request data whenever someone tries to log a message. For this I would like to create a helper method like so
function log_message(level, message){
winston.log(level, req.path + "" + message);
}
I would then use the method like so.
exports.index = function(req, res){
log_message("info", "I'm here");
}
Note that I am not passing the req object to the log_message function. I want that to be transparently done so that the log_message API user does not need to be aware of the common data that is being logged.
Is there a way to achieve this with express.js/node.js. Is the request object available from a global variable of some sort?
© Stack Overflow or respective owner