Skip to content

Router options ​

NestjsEndpoints.forRoot() ​

ts
import { Module } from '@nestjs/common';
import { NestjsEndpoints } from 'nestjs-endpoints';

@Module({
  imports: [
    NestjsEndpoints.forRoot({
      router: { /* options */ },
    }),
  ],
})
export class AppModule {}

Sets the library up for an app, and creates its root router. Call it once, in the app's root module: a second call fails the start.

OptionType
routerthe router optionsThe app's root router. Its rootDirectory is relative to the file that calls forRoot(). An app made only of routers it imports can leave router out.
watchbooleanWhether the app watches its endpoint folders, so that node --watch restarts it when an endpoint file is added or removed. nest start --watch restarts by itself. The app keeps a small file per router under node_modules/.cache/nestjs-endpoints/ for it. Defaults to false. See Development.

forRoot() returns what create() returns.

EndpointRouterModule.create() ​

ts
import { EndpointRouterModule } from 'nestjs-endpoints';

export default EndpointRouterModule.create({ /* options */ });

Creates every router but the root one: a nested router, or one a module imports beside the root router.

create() returns a promise of a NestJS dynamic module. Pass it to a module's imports, or default-export it from a router.module.ts for a parent router to find.

The returned promise also has an endpoint property: the router's own endpoint.query() and endpoint.mutation() builders, which add the router's endpointConfig to the endpoints built with them.

Options ​

OptionType
rootDirectorystring | string[]The folder to look for endpoint files in, relative to the calling file, or several, all under the same basePath. Defaults to the calling file's own folder.
basePathstringThe URL prefix of everything the router owns. Inferred when left out. '' or '/' mounts the router at the root.
namespaceboolean | stringThe router's namespace in the generated clients. It does not affect URLs.
descriptionstringDocuments the router's namespace: a comment on it in the generated clients.
endpointsarray of endpoints, or a function returning endpoints and import()sEndpoints registered by hand. They get the router's basePath.
middlewarearray of NestMiddleware classes and functionsMiddleware for every endpoint under the router. Its last entry may be { exclude: string[] }, with paths relative to basePath.
interceptorsarray of interceptor classes or instancesInterceptors for every endpoint under the router.
guardsarray of guard classes or instancesGuards for every endpoint under the router.
endpointConfig{ inject?, injectOnRequest? }Injections for every endpoint built with the router's endpoint. Shaped as the endpoint options of the same names.
imports, providers, exportsas in @Module()The module's own.

How a router finds endpoint files and builds their URLs is in File-based routing, and how it finds nested routers in Routers.

Released under the MIT License.