Can not get req.params in router middleware
See original GitHub issue// hasProjectPremission List this
hasProjectPremission = (req, res, next) => {
console.log(req.params); // {}
next();
}
router.use(apiBiz.hasProjectPremission);
router.post('/:projId/api/new', apiBiz.createApi);
When request to the create api, I can’t get req.params in hasProjectPremission
, it’s an empty object({})。
Issue Analytics
- State:
- Created 7 years ago
- Comments:9 (3 by maintainers)
Top Results From Across the Web
Express middleware access to req.params - node.js
I have middleware that is being called before I initialize my routes ( app.use(middleware) ), and it can't get req.params ., but it...
Read more >Express Explained with Examples - Installation, Routing ...
Middleware functions are useful pattern that allows developers to reuse code within their applications and even share it with others in the form ......
Read more >Error handling - Express.js
You must catch errors that occur in asynchronous code invoked by route handlers or middleware and pass them to Express for processing. For...
Read more >Parse Request middleware - API Dev Tools
use("/users/:id", myMiddleware) ), then req.params will have a property for each path parameter ( id in this example). Thus, req.params changes as it...
Read more >Express Tutorial Part 4: Routes and controllers - MDN Web Docs
In the case above we complete the request using send() , so the next argument is not used (and we choose not to...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Actually middleware can get parameters from router, but it needs to know which one.
for example:
But IMO you should use router.param which will act like an middleware, executed right before route is handled.
@aPoCoMiLogin Very thanks.