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
‹ swipe to step through ›
Walkthrough
Space play
←→ step
click any line
Three takeaways
- 1A NestJS module is a manifest: it declares dependencies and boundaries rather than containing logic itself.
- 2Only providers listed in exports are visible to other modules, giving each feature a controlled public surface.
- 3Importing other modules lets their exported providers be injected here without re-registering them.
Related explainers
typescript
import { Component, ChangeDetectionStrategy, inject, signal } from '@angular/core'; import { CommonModule } from '@angular/common'; import { ScrollingModule } from '@angular/cdk/scrolling'; import { toObservable } from '@angular/core/rxjs-interop';
Virtual scrolling a contact list in Angular
virtual-scrolling
signals
change-detection
Intermediate
6 steps
typescript
import { Controller, Get, Query,
Validating paginated queries in NestJS
pagination
validation
pipes
Intermediate
7 steps
python
import pytest from fastapi.testclient import TestClient from sqlalchemy import create_engine from sqlalchemy.orm import sessionmaker
Testing FastAPI routes with dependency overrides
testing
fixtures
dependency-injection
Intermediate
7 steps
typescript
import { AsyncLocalStorage } from 'node:async_hooks'; import { randomUUID } from 'node:crypto'; import { Injectable, NestMiddleware } from '@nestjs/common'; import { Request, Response, NextFunction } from 'express';
Request correlation IDs in NestJS with AsyncLocalStorage
async-local-storage
middleware
logging
Advanced
8 steps
typescript
import { Controller, Post, UploadedFile,
Handling avatar uploads in NestJS
file-upload
validation
interceptors
Intermediate
7 steps
typescript
@Component({ selector: 'app-article-editor', templateUrl: './article-editor.component.html', })
Autosaving a form with RxJS in Angular
reactive-forms
rxjs-operators
debouncing
Advanced
8 steps
Share this explainer
Here's the card — post it anywhere.
Made with highlit — turn any snippet into a walkthrough like this in about a minute.
Explain your code
Embed this explainer
Drop the interactive walkthrough into a blog or docs. Views never cost a credit.
<iframe src="https://highlit.co/explainers/how-a-nestjs-feature-module-wires-up-explained-typescript-3611/embed?autoplay=1" width="100%" height="520" loading="lazy" style="border:0"></iframe>
Autoplay is on by default — add ?autoplay=0 to start paused.