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

typescript
import { registerLocaleData } from '@angular/common';
import localeFr from '@angular/common/locales/fr';
import localeFrExtra from '@angular/common/locales/extra/fr';
import localeDe from '@angular/common/locales/de';

Locale-aware bootstrapping in Angular

i18n localization dependency-injection
Intermediate 8 steps
typescript
import { Module } from '@nestjs/common';
import { ConfigModule } from '@nestjs/config';
import * as Joi from 'joi';
 

Validating env config at boot in NestJS

configuration schema-validation environment-variables
Intermediate 8 steps
java
@Component
@Converter
public class EncryptedStringConverter implements AttributeConverter<String, String> {
 

Transparent column encryption in Spring & JPA

encryption aes-gcm jpa-converter
Advanced 10 steps
typescript
import { Inject, Injectable, Logger } from '@nestjs/common';
import { CACHE_MANAGER } from '@nestjs/cache-manager';
import { Cache } from 'cache-manager';
import { InjectRepository } from '@nestjs/typeorm';

A cache-aside country lookup in NestJS

cache-aside dependency-injection batch-lookup
Intermediate 8 steps
java
package com.acme.billing.config;
 
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.ConfigurationProperties;

Feature-flagged beans with Spring @ConditionalOnProperty

feature-flags conditional-beans strategy-pattern
Intermediate 5 steps
typescript
import { Injectable, effect, signal, computed } from '@angular/core';
 
interface Preferences {
  theme: 'light' | 'dark';

A signal-based preferences store in Angular

signals state-management persistence
Intermediate 7 steps

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