Reputation: 4004
In express you call var app = module.exports = express.createServer();
which creates a new HTTPServer
object. I'd like to get access to the current req
object from this app
(HTTPServer
) object. Is there a way to do this?
Upvotes: 4
Views: 1716
Reputation: 15003
The req
object is only created when the underlying HTTPServer
actually gets a request, and only lasts for as long as the request is processed. So it's not really meaningful to talk about it outside the context of a callback.
During a callback, you can simply copy the appropriate data from the session object somewhere else and use that copy in your websockets code. But you can't count on the request object, or even the session object, remaining after you've finished processing the request.
Showing a small code example would be helpful; it sounds like you've got an "XY problem" (you want to accomplish a goal X and you've decided that technique Y is the right way to do it, when in fact technique Z might work better).
Upvotes: 6