nest-router is a module for the NestJS framework designed to provide a hierarchical and modular approach to route organization. It allows developers to define a tree-like structure for application routes, automatically prefixing controller paths based on parent module configurations. For example, a child module's routes will inherit the parent's prefix, resulting in `/parent/child/route` rather than just `/child/route`. This addresses a common routing organization challenge in older NestJS versions (specifically prior to features like `APP_BASE_URL` or later routing enhancements). The last stable version is 1.0.9, published 7 years ago. This package is largely incompatible with modern NestJS versions (v6+ and especially v10+, with NestJS 11.1.19 being the latest as of April 2026). Its primary differentiator was its ability to structure routes in a more organized, tree-like manner for NestJS applications relying on a specific routing pattern.
npm install nest-routerVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to define a hierarchical route structure using `nest-router` and integrate it into a NestJS application. It shows how parent modules define prefixes for their children's routes.
Do not use `nest-router` with modern NestJS applications. Consider using native NestJS module-based routing (`prefix` option in `@Module` decorator for controllers) or implementing custom route-prefixing logic if hierarchical routing is required.
Migrate away from this package to current NestJS routing practices or more actively maintained alternatives. Remove it from your `package.json`.
Always consider the full hierarchical path when designing route structures and referencing endpoints. Test generated routes thoroughly.
Always use `RouterModule.resolvePath(SomeController)` when applying middleware to controllers managed by `nest-router` to ensure the correct, fully-prefixed path is used.
Ensure `RouterModule` is correctly imported via `import { RouterModule } from 'nest-router';` and `RouterModule.forRoutes(routes)` is added to the `imports` array of your root module (e.g., `ApplicationModule`). Also, ensure all modules specified in your `Routes` array are also imported directly into the parent module importing `RouterModule.forRoutes`.Verify the import statement `import { RouterModule } from 'nest-router';` is present and correct. This typically happens if `RouterModule` is not imported as a named export.When using `nest-router`, apply middleware using `forRoutes(RouterModule.resolvePath(SomeController))` to ensure NestJS uses the full, hierarchically prefixed path for the controller.