The first thing that NestJS borrows from Angular is its abstractions, such as modules that allow us to decompose our applications and properly isolate features/concerns.
NestJS modules are almost exactly the same as Angular modules.
They can also be created using the NestJS CLI:
npx @nestjs/cli generate module helloworld
Once again, this is the same command as we could use with the Angular CLI.
Let's look at the generated module file, which you can find in the code samples of this book, under Chapter11/12-NestJS/src/helloworld/helloworld.module.ts:
import { Module } from '@nestjs/common'; @Module({}) export class HelloworldModule {}
Do you see anything surprising? No? Exactly! There are no surprises here!
Now you probably wonder whether there is also an App module as with Angular. And yes, there is!
Here's what it looks like in our hello world NestJS example:
import { Module } from '@nestjs/common'; import { AppController } from './app.controller'; import { AppService } from './app.service'; import { HelloworldModule } from './helloworld/helloworld.module'; @Module({ imports: [HelloworldModule], controllers: [AppController], providers: [AppService], }) export class AppModule {}
Notice again the familiar @Module decorator. Its properties are also similar: we can see an array of imports and an array of providers, exactly like Angular's.