In this post, we look at how to create a NestJS provider with detailed examples to understand how we can use them in our application.
Join the DZone community and get the full member experience. In this post, we will be looking at NestJS Providers and how to use them in our application. In the previous post, we looked into NestJS Controllers. It is important to know about controllers before learning about Providers in NestJS and therefore, I will recommend you go through that post before starting this one. The main concept behind Providers and NestJS, in general, is Dependency Injection. But what is Dependency Injection? In a nutshell, Dependency Injection is a design pattern in which a class requests for its dependencies from an external source rather than creating them. This external source can be the framework itself. Since NestJS uses Typescript as a base, it becomes extremely easy to manage dependencies. If you come from a background of other frameworks such as Spring Boot that utilize Dependency Injection, it will be immediately obvious to you. However, even if you are completely new to this topic, we will see detailed examples that will make things clear. The main idea behind a Provider is that it can be injected as a dependency.