What is NestJS

overview

NestJS is a progressive web application framework for Node.js. NestJS is inspired by Angular’s architecture and adopts many Angular concepts. This allows you to apply design principles, patterns, and best practices like those used in Angular to your Node.js applications.

NestJS has a modularized architecture that can improve code reusability, ORM (Object-Relational Mapping) for database access, routing for handling HTTP requests, and helps you write testable code. It provides features such as dependency injection that

NestJS supports both TypeScript and JavaScript. It is also built on top of popular server-side frameworks such as Express and fastify and can be integrated into existing Node.js applications. NestJS also focuses on scalability and performance, offering features like asynchronous processing and microservices.

Main features of NestJS

  1. Module-based architecture NestJS allows you to organize your application in modules. This makes it possible to divide code by function and improve reusability and maintainability.
  2. Support for many web frameworks such as express, fastify NestJS supports many web frameworks, including Express and fastify, which are the frameworks of choice for developing web applications.
  3. Dependency Injection (DI) support NestJS can manage dependencies between application components using dependency injection. This allows for looser coupling between components for better testing and maintainability.
  4. Abundant filter functions such as guards, pipes, interceptors, etc. NestJS provides various filtering capabilities for requests and responses in your application. This makes it easy to ensure security and data integrity.
  5. WebSocket and gRPC support NestJS supports real-time communication protocols such as WebSockets and gRPC. This makes it easier to build real-time communication applications.

NestJS Key Benefits/Benefits

  1. Rapid and efficient development with CLI The Nest CLI makes it easy to create or generate new applications and modules. In addition, various configuration files and dependencies can be managed using the CLI, allowing developers to focus on their code.
  2. Highly maintainable application development with TypeScript and dependency injection TypeScript enables static typing, allowing developers to make their code more reliable. Dependency injection also makes it easier to test and develop maintainable applications.
  3. Large community and support system NestJS has a large community, with tons of documentation, libraries, and plugins. Additionally, there are plenty of support systems such as StackOverflow and GitHub, making it easy for developers to find the information they need to solve their problems.
  4. Support for MVC development with Node.js NestJS supports MVC development with Node.js. This simplifies web application development and allows developers to organize their code according to controller, model, and view roles.
  5. Modularity and scalability NestJS provides a module system for dividing functionality into reusable units. This modular system makes it easy to extend and scale your application.
  6. Structured code NestJS uses a component-based architecture to keep your application structure clean. This architecture makes your application code cleaner and easier to read.
  7. Testability NestJS uses an application structure based on dependency injection, which makes it easy to unit test. Dependency injection allows components to be tested in isolation, making it easier to test the entire application.
  8. Easy-to-understand documentation NestJS comes with clear documentation to help developers get started. The documentation includes how to create the application, architecture description, how to use plugins, and more.
  9. Platform Choices NestJS can work on multiple platforms (Node.js, Browsers, React Native). This allows the same code to be shared across multiple platforms.
  10. Abundant functions and expandability NestJS has many built-in features such as HTTP request handling, WebSocket support, CLI tools, ORM support, and more. NestJS is also highly community extensible, so you can extend your application even further with third-party packages and modules.

Compared to other Node.js frameworks, it is influenced by front-end frameworks such as Angular, React, and Vue, thus providing flexible system development and ease of testing through dependency injection. increase.

For these reasons, NestJS is ideal for developing large scale backend systems.

NestJS architecture

NestJS is a modular framework for Node.js designed to simplify building applications. The NestJS architecture consists of the following components:

  1. Module Modules are a way of dividing functionality into logical, reusable units within an application. A module can bring together related providers, controllers, routing logic, and related components. Modules have some metadata, including imports, exports, and providing providers to configure your NestJS application.
  2. Provider Providers are a means of providing dependencies used by your application. Providers are injected into other providers or controllers in modules using the DI (Dependency Injection) principle. Providers can be used in the form of services, repositories, factories, helpers, interceptors, etc.
  3. Controller A controller is a means of returning a response to an HTTP request. Controllers are designed to correspond to specific endpoints in your application. Each controller has a list of associated HTTP methods (GET, POST, PUT, etc.) and URL endpoints. While processing the request, the controller can optionally use providers to perform business logic.
  4. Interceptor An interceptor is a function that runs inside the request pipeline. These can be used to modify the request or response before the request is processed or before the response is sent. For example, it can be used for authentication, caching, logging, etc.
  5. Middleware Middleware can be used to modify, validate, or authorize requests. For example, you can use middleware to log requests or perform authentication. Middleware is provided in the @nestjs/common package.
  6. Guard Guards can approve requests. Guards can be used to validate requests before processing them. For example, guards can be used for authentication and authorization. Guards are provided in the @nestjs/common package.
  7. Pipe Pipes can be applied to controller method arguments and return values, or filter arguments. Pipes can be used, for example, to reformat request input data or to perform validations. Pipes are provided by the @nestjs/common package.

The NestJS architecture consists of various components such as modules, providers, controllers, interceptors, middleware, guards, and pipes, each of which has a role to play in streamlining application development.

Companies using NestJS

The following sites are websites that use Nest.js.

  • https://www.sanofi.com/
  • https://shop.adidas.jp/
  • https://www.autodesk.com/
  • https://particuliers.societegenerale.fr/
  • https://www.roche.com/
  • https://www.rewe-digital.com/
  • https://www.capgemini.com/
  • https://www.decathlon.com/

It is used by famous companies such as Roche and Adidas, which shows the high degree of perfection of nestJS.

lastly

NestJS makes it easy to develop robust and secure backend applications by enforcing rules-based development from start to finish.

It also uses the latest solutions and technologies, so NestJS itself will never become obsolete. Therefore, you can develop applications that are easy to maintain without thinking about anything.

If you feel NestJS is a great framework, you can start developing right away. Just do an npm install and run the Nest CLI.

npm i -g @nestjs/cli
nest new project-name

If you want to know more about how to set up the environment, please refer to “[Introduction to NestJS from inexperienced | Environment construction] (https://wiblok.com/ts/nest/nest_setup/)”.

that’s all.