typescript 25 lines · 7 steps

How a NestJS feature module wires up

An @Module decorator declares what a feature imports, exposes over HTTP, provides for injection, and shares with other modules.

Explained by highlit
1import { Module } from '@nestjs/common';
2import { TypeOrmModule } from '@nestjs/typeorm';
3import { BullModule } from '@nestjs/bullmq';
4 
5import { OrdersController } from './orders.controller';
6import { OrdersService } from './orders.service';
7import { OrderPricingService } from './order-pricing.service';
8import { OrderFulfillmentProcessor } from './order-fulfillment.processor';
9import { Order } from './entities/order.entity';
10import { OrderItem } from './entities/order-item.entity';
11import { PaymentsModule } from '../payments/payments.module';
12import { InventoryModule } from '../inventory/inventory.module';
13 
14@Module({
15 imports: [
16 TypeOrmModule.forFeature([Order, OrderItem]),
17 BullModule.registerQueue({ name: 'order-fulfillment' }),
18 PaymentsModule,
19 InventoryModule,
20 ],
21 controllers: [OrdersController],
22 providers: [OrdersService, OrderPricingService, OrderFulfillmentProcessor],
23 exports: [OrdersService, OrderPricingService],
24})
25export class OrdersModule {}
01 / 01
STEP 01

Walkthrough

Space play step click any line
Three takeaways
  1. 1A NestJS module is a manifest: it declares dependencies and boundaries rather than containing logic itself.
  2. 2Only providers listed in exports are visible to other modules, giving each feature a controlled public surface.
  3. 3Importing other modules lets their exported providers be injected here without re-registering them.

Related explainers

Share this explainer

Here's the card — post it anywhere.

How a NestJS feature module wires up — share card
Made with highlit — turn any snippet into a walkthrough like this in about a minute.
Explain your code