Is it possible to access my query params in my views in ExpressJS 3?
I have a url: http://example.com?search=blah
And in my view I would like to access the search param
I can pass it as a locals but wondering if I can access it directly – my experiments were not successful.
Not looking for the pros and cons of direct access – just want to know if it’s possible and how.
Here are a few ways to access
req.queryfrom your view:Set it as a local in the call to
renderin your view you can access
searchasquery.search.Set
res.localsin your view you can access
searchasquery.search.Use middleware
This is similar to the previous example but we can use middleware in a reusable way.
Any route that uses the above middleware, will have
res.locals.queryset.edit
It appears that I misunderstood the question. The intent was to see if the request data could be accessed without use of the above techniques. As far as I know, it can not. Hopefully the above will still be useful for some readers.