Yes. Mount one router inside another: router.use('/:userId/posts', postsRouter). Now /users/:userId/posts/... hits postsRouter. Limit nesting to one level; for deeper resources, use a separate top-level router with a filter.
Express Router Mounting and Nesting Explained
Can you nest Express routers?
The answer
More FAQs in Express Router Mounting and Nesting Explained
app.use('/path', router). The router's paths are then relative to /path. For example, router.get('/:id') mounted at /users responds to /users/:id. Mount in app.js to keep it thin.
router.use(middleware) at the top of the router file applies the middleware to every route in the router. Useful for auth and role checks across a feature without repeating per route.
Deep nesting (e.g., /users/:userId/posts/:postId/comments/:commentId) makes URLs long, rigid, and hard to refactor. Use a separate top-level router with a filter (?post=postId) for deeper resources. Keeps URLs clean.
Still have questions?
Browse all our FAQs or reach out to our support team
Want to upskill yourself?
Your learning library
Small steps. Big possibilities.
Find your next course. Build something great.