Registry / web-framework / nest-router

nest-router

JSON →
library1.0.9jsnpmunverified

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-router
INSTALL
IMPORT
SIG · NEST-ROUTER
N
nest-router
web-frameworkjavascriptv1.0.9
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

RouterModule
import { RouterModule } from 'nest-router';
const RouterModule = require('nest-router');
NestJS projects are typically TypeScript and use ESM-style imports.
Routes
import { Routes } from 'nest-router';
import Routes from 'nest-router';
Routes is a named type/interface, not a default export.
forRoutes
RouterModule.forRoutes(routes);
new RouterModule().forRoutes(routes);
forRoutes is a static method on RouterModule, used directly from the class.
resolvePath
RouterModule.resolvePath(SomeController);
new RouterModule().resolvePath(SomeController);
resolvePath is a static utility method for middleware path resolution.

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.

import { Module } from '@nestjs/common'; import { RouterModule, Routes } from 'nest-router'; // Imagine these are actual NestJS modules with controllers class CatsModule {} class DogsModule {} class NinjaModule {} const routes: Routes = [ { path: '/ninja', module: NinjaModule, children: [ { path: '/cats', module: CatsModule, }, { path: '/dogs', module: DogsModule, }, ], }, ]; @Module({ imports: [ RouterModule.forRoutes(routes), // Set up the routes hierarchy CatsModule, DogsModule, NinjaModule // All modules must also be imported normally ], }) export class ApplicationModule {} // Example of how a controller path would resolve: // A controller in CatsModule with @Controller('my-cat') // would have a full path of /ninja/cats/my-cat
Debug
Known issues
breakingThe `nest-router` package is designed for NestJS versions greater than 4.5.10. It is largely incompatible with modern NestJS versions (v6+ and especially v10+). Attempting to use this package with current NestJS releases will likely result in compilation errors or runtime failures due to significant API changes in the core framework over the past several years.
fix
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.
affects: >=1.0.0
breakingThis package has been abandoned for over 7 years. It receives no updates, bug fixes, or security patches, making it a potential security vulnerability and functionally obsolete for modern development practices. Relying on it is strongly discouraged.
fix
Migrate away from this package to current NestJS routing practices or more actively maintained alternatives. Remove it from your `package.json`.
affects: >=1.0.0
gotchaWhen defining nested routes, child module controllers will be prefixed by the full path of their parent and grandparent modules, not just their immediate parent. For example, a controller in `CatsModule` (child of `NinjaModule` with path `/ninja`) will resolve to `/ninja/cats/controller-path`, not `/cats/controller-path`.
fix
Always consider the full hierarchical path when designing route structures and referencing endpoints. Test generated routes thoroughly.
affects: >=1.0.0
gotchaNestJS middleware often requires the full resolved path of a controller, which `nest-router`'s module prefixes affect. Standard `forRoutes(SomeController)` in middleware may not work as expected.
fix
Always use `RouterModule.resolvePath(SomeController)` when applying middleware to controllers managed by `nest-router` to ensure the correct, fully-prefixed path is used.
affects: >=1.0.0
Errors
Common errors & fixes
Nest can't resolve dependencies of the ApplicationModule (?). Please make sure that the argument RouterModule is available in the current context.
The `RouterModule` or its dependencies were not properly imported or provided within the NestJS module.
fix
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`.
TypeError: Cannot read properties of undefined (reading 'forRoutes')
Attempting to call `forRoutes` on `RouterModule` before `RouterModule` itself has been correctly imported or when the imported symbol is undefined.
fix
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.
Error: Nest can't resolve dependencies of the SomeMiddleware (?). Please make sure that the argument SomeController is available in the current context.
Middleware is being applied to a controller using `forRoutes(SomeController)` without considering `nest-router`'s path resolution, leading to an incorrect path lookup.
fix
When using `nest-router`, apply middleware using `forRoutes(RouterModule.resolvePath(SomeController))` to ensure NestJS uses the full, hierarchically prefixed path for the controller.
Upgrade
Version history
1.0.9latest on npm
Audit
Dependencies
@nestjs/commonrequiredCore NestJS framework peer dependency, explicitly requires Nest > v4.5.10+
@nestjs/corerequiredCore NestJS framework peer dependency, explicitly requires Nest > v4.5.10+
Agent activity
2 hits · last 30 days
node
2
Resources
nest-router — npm install nest-router · libregistry