Access current req object everywhere in Node.js Express
<p>I wonder how to access req object if there's no 'req' parameter in callback.</p>

<p>This is the scenario：<br>
In ExpressJs, I have a common function, it uses to handle something with 'req' object, but not pass req into it.</p>

<pre><code>module.exports = {
    get: function(){
        var req = global.currentRequest;
        //do something...
    }
}
</code></pre>

<p>My current solution is that I write a middleware for all request, I put the 'req' in global variable, then I can access the 'req' everywhere with 'global.currentRequest'. </p>

<pre><code>// in app.js
app.use(function (req, res, next) {
    global.currentRequest= req;
    next();
});
</code></pre>

<p>But I don't know if it's good? Can anyone have suggestions?<br>
Thanks a lot!</p>