Router Module For Nestjs Framework ๐Ÿšฆ ๐Ÿš€
TypeScript JavaScript
Switch branches/tags
Nothing to show
Fetching latest commitโ€ฆ
Cannot retrieve the latest commit at this time.

Nest Router ๐Ÿšฆ

Greenkeeper badge Build Status npm version Coverage Status

Router Module For Nestjs Framework

Quick Overview

RouterModule Will Help you to organize your Routes and it Will give you the ability to create a routes tree.

How ?

Every Module could have a path property that path will be a prefix for all Controllers in this Module, then if that Module have a parent, it will be a child of it and again all Controllers in this child modules will be prefixed by parent module prefix + this module prefix

see issue #255 .


IMPORTANT: you will need Nest > v4.5.10+

npm install nest-router --save


yarn add nest-router


See How it easy to setup.

... //imports
const routes: Routes = [
      path: '/ninja',
      module: NinjaModule,
      children: [
          path: '/cats',
          module: CatsModule,
          path: '/dogs',
          module: DogsModule,

  imports: [
      RouterModule.forRoutes(routes), // setup the routes
      ], // as usual, nothing new
export class ApplicationModule {}

๐Ÿ‘ TIP: Keep all of your Routes in a sprate file like routes.ts

in this example the all the controllers in NinjaModule will be prefixed by /ninja then it have a 2 childs CatsModule and DogsModule.

again, all controllers CatsModule will be prefixed by /cats Right ?, NO!! ๐Ÿ˜ฎ , the CatsModule is a child of NinjaModule so it will be prefixed by /ninja/cats/ path insted. and so DogsModule.

See example folder for more information.

Example Folder Project Structure

โ”œโ”€โ”€ app.module.ts
โ”œโ”€โ”€ cats
โ”‚ย ย  โ”œโ”€โ”€ cats.controller.ts
โ”‚ย ย  โ”œโ”€โ”€ cats.module.ts
โ”‚ย ย  โ””โ”€โ”€ ketty.controller.ts
โ”œโ”€โ”€ dogs
โ”‚ย ย  โ”œโ”€โ”€ dogs.controller.ts
โ”‚ย ย  โ”œโ”€โ”€ dogs.module.ts
โ”‚ย ย  โ””โ”€โ”€ puppy.controller.ts
โ”œโ”€โ”€ main.ts
โ””โ”€โ”€ ninja
    โ”œโ”€โ”€ katana.controller.ts
    โ”œโ”€โ”€ ninja.controller.ts
    โ””โ”€โ”€ ninja.module.ts

and here is a simple nice route tree of example folder

    โ”œโ”€โ”€ /
    โ”œโ”€โ”€ /katana
    โ”œโ”€โ”€ cats
    โ”‚ย ย  โ”œโ”€โ”€ /
    โ”‚ย ย  โ””โ”€โ”€ /ketty
    โ”œโ”€โ”€ dogs
 ย ย      โ”œโ”€โ”€ /
 ย ย      โ””โ”€โ”€ /puppy

Nice !


See CHANGELOG for more information.


you are welcome with this project for contributing, just make a PR


  • Shady Khalifa - Initial work

See also the list of contributors who participated in this project.


This project is licensed under the MIT License - see the file for details