Dependency injection

This brings us to the feature that NestJS borrows from Angular: DI. Once again, it works exactly like with Angular.

In reality, the whole API of NestJS is very close to the Angular API. Kamil Mysliwiec, the author of NestJS, did this on purpose, to limit the mental overhead of learning another framework with its own specific universe. Thanks to this, NestJS is really easy to learn for anyone already familiar with Angular.

Just like with Angular, we can use an @Injectable decorator to declare injectable elements, define providers, and easily inject instances where required.

One (important) difference between NestJS and Angular providers is the fact that NestJS providers are private by default. This means that they have to be exported to be made publicly available. Angular works in the opposite way; providers are public by default and are globally accessible unless otherwise specified.

Let's look at controllers and routing.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.47.253