NestJS

Nest Module decorator

A NestJS module declares a group of controllers and providers. Controllers receive transport requests; providers hold reusable application behavior. The @Module decorator declares module metadata. @Controller sets a route prefix and @Get selects a method and optional path. The default HTTP adapter is Express in the standard Nest setup; alternative adapters exist. Nest uses TypeScript decorators and metadata in typical projects; configure the reviewed compiler before attempting these examples. An exported provider may be used by a module that imports its owning module. Static example only; runtime NOT RUN. Source: https://docs.nestjs.com/modules.

Formal Syntax & Structure

nodejs syntaxnodejs
@Module({ imports, controllers, providers, exports })

Working Example

Example Snippetnodejs
import { Controller, Get, Injectable, Module } from '@nestjs/common';@Injectable()class CatalogService {  list() { return [{id:'p1', title:'Notebook'}]; }}@Controller('catalog')class CatalogController {  constructor(private readonly service: CatalogService) {}  @Get() list() { return this.service.list(); }}@Module({controllers:[CatalogController],providers:[CatalogService]})export class CatalogModule {}
Node.js Reference