0
0
NestJSframework~30 mins

Module re-exporting in NestJS - Mini Project: Build & Apply

Choose your learning style9 modes available
NestJS Module Re-exporting
📖 Scenario: You are building a NestJS application that has two feature modules: UsersModule and AuthModule. You want to create a SharedModule that re-exports these two modules so other parts of the app can import just the SharedModule to get access to both.
🎯 Goal: Build a SharedModule that imports and re-exports UsersModule and AuthModule so other modules can use their providers by importing only SharedModule.
📋 What You'll Learn
Create a UsersModule with a simple provider
Create an AuthModule with a simple provider
Create a SharedModule that imports and re-exports UsersModule and AuthModule
Use NestJS module syntax with @Module decorator and imports and exports arrays
💡 Why This Matters
🌍 Real World
In real NestJS apps, re-exporting modules via a SharedModule helps keep imports clean and organized. It lets you group related modules and share their providers easily.
💼 Career
Understanding module re-exporting is important for building scalable NestJS applications and working in teams where modular architecture is required.
Progress0 / 4 steps
1
Create UsersModule with a provider
Create a NestJS module called UsersModule that provides a class called UsersService. Use the @Module decorator with a providers array containing UsersService.
NestJS
Need a hint?

Remember to export UsersService and include it in both providers and exports arrays so it can be used outside the module.

2
Create AuthModule with a provider
Create a NestJS module called AuthModule that provides a class called AuthService. Use the @Module decorator with a providers array containing AuthService and export AuthService as well.
NestJS
Need a hint?

Follow the same pattern as UsersModule but for AuthService and AuthModule.

3
Create SharedModule importing UsersModule and AuthModule
Create a NestJS module called SharedModule that imports UsersModule and AuthModule. Use the @Module decorator with an imports array containing UsersModule and AuthModule.
NestJS
Need a hint?

Use both imports and exports arrays in @Module to re-export the imported modules.

4
Use SharedModule in another module
Create a NestJS module called AppModule that imports only the SharedModule. Use the @Module decorator with an imports array containing SharedModule.
NestJS
Need a hint?

This shows how other modules can import SharedModule to get access to UsersModule and AuthModule providers.