{"id":11384,"library":"nest-router","title":"Nest Router Module","description":"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.","status":"abandoned","version":"1.0.9","language":"javascript","source_language":"en","source_url":"https://github.com/shekohex/nest-router","tags":["javascript","nestjs","router","addons"],"install":[{"cmd":"npm install nest-router","lang":"bash","label":"npm"},{"cmd":"yarn add nest-router","lang":"bash","label":"yarn"},{"cmd":"pnpm add nest-router","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Core NestJS framework peer dependency, explicitly requires Nest > v4.5.10+","package":"@nestjs/common","optional":false},{"reason":"Core NestJS framework peer dependency, explicitly requires Nest > v4.5.10+","package":"@nestjs/core","optional":false}],"imports":[{"note":"NestJS projects are typically TypeScript and use ESM-style imports.","wrong":"const RouterModule = require('nest-router');","symbol":"RouterModule","correct":"import { RouterModule } from 'nest-router';"},{"note":"Routes is a named type/interface, not a default export.","wrong":"import Routes from 'nest-router';","symbol":"Routes","correct":"import { Routes } from 'nest-router';"},{"note":"forRoutes is a static method on RouterModule, used directly from the class.","wrong":"new RouterModule().forRoutes(routes);","symbol":"forRoutes","correct":"RouterModule.forRoutes(routes);"},{"note":"resolvePath is a static utility method for middleware path resolution.","wrong":"new RouterModule().resolvePath(SomeController);","symbol":"resolvePath","correct":"RouterModule.resolvePath(SomeController);"}],"quickstart":{"code":"import { Module } from '@nestjs/common';\nimport { RouterModule, Routes } from 'nest-router';\n\n// Imagine these are actual NestJS modules with controllers\nclass CatsModule {}\nclass DogsModule {}\nclass NinjaModule {}\n\nconst routes: Routes = [\n  {\n    path: '/ninja',\n    module: NinjaModule,\n    children: [\n      {\n        path: '/cats',\n        module: CatsModule,\n      },\n      {\n        path: '/dogs',\n        module: DogsModule,\n      },\n    ],\n  },\n];\n\n@Module({\n  imports: [\n    RouterModule.forRoutes(routes), // Set up the routes hierarchy\n    CatsModule,\n    DogsModule,\n    NinjaModule // All modules must also be imported normally\n  ],\n})\nexport class ApplicationModule {}\n\n// Example of how a controller path would resolve:\n// A controller in CatsModule with @Controller('my-cat')\n// would have a full path of /ninja/cats/my-cat\n","lang":"typescript","description":"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."},"warnings":[{"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.","message":"The `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.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Migrate away from this package to current NestJS routing practices or more actively maintained alternatives. Remove it from your `package.json`.","message":"This 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.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Always consider the full hierarchical path when designing route structures and referencing endpoints. Test generated routes thoroughly.","message":"When 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`.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Always use `RouterModule.resolvePath(SomeController)` when applying middleware to controllers managed by `nest-router` to ensure the correct, fully-prefixed path is used.","message":"NestJS 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.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"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`.","cause":"The `RouterModule` or its dependencies were not properly imported or provided within the NestJS module.","error":"Nest can't resolve dependencies of the ApplicationModule (?). Please make sure that the argument RouterModule is available in the current context."},{"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.","cause":"Attempting to call `forRoutes` on `RouterModule` before `RouterModule` itself has been correctly imported or when the imported symbol is undefined.","error":"TypeError: Cannot read properties of undefined (reading 'forRoutes')"},{"fix":"When using `nest-router`, apply middleware using `forRoutes(RouterModule.resolvePath(SomeController))` to ensure NestJS uses the full, hierarchically prefixed path for the controller.","cause":"Middleware is being applied to a controller using `forRoutes(SomeController)` without considering `nest-router`'s path resolution, leading to an incorrect path lookup.","error":"Error: Nest can't resolve dependencies of the SomeMiddleware (?). Please make sure that the argument SomeController is available in the current context."}],"ecosystem":"npm"}