Here are some ways to access req.query from your view:
Set it as local in the render call
function(req, res) { res.render('myview', {query: req.query}); };
in your view, you can access search as query.search .
Install res.locals
function(req, res) { res.locals.query = req.query; res.render('myview'); };
in your view, you can access search as query.search .
Use middleware
This is similar to the previous example, but we can use the middleware in reusable mode.
function(req, res, next) { res.locals.query = req.query; next(); };
Any route that uses the above middleware will have res.locals.query .
change
It seems I did not understand this question. The goal was to see if it was possible to access the query data without using the above methods. As far as I know, this is not possible. We hope that the above will continue to be useful to some readers.
source share