# NestJS Guide

Summary

1.  NestJS Introduction
2.  NestJS Concepts
3.  NestJS Coding
4.  References

### 1\. NestJS Introduction

### Hello, nest!

#### A progressive Node.js framework for building efficient, reliable and scalable server-side applications.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1662174897726/iRt8ky8Ar.png)

[https://nestjs.com/](https://nestjs.com/)

[**GitHub - nestjs/nest: A progressive Node.js framework for building efficient, scalable, and…**  
*A progressive Node.js framework for building efficient, scalable, and enterprise-grade server-side applications on top…*github.com](https://github.com/nestjs/nest "https://github.com/nestjs/nest")[](https://github.com/nestjs/nest)

### Comapre NestJS vs NodeJS

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1662174899016/Mkoum6S_E.jpeg)

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1662174900292/CuAPnjL1p.png)

### Types of NodeJS Frameworks

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1662174901619/mC-xE7Qxl.png)

NodeJS Frameworks

### Some statistics

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1662174902914/H3sDBo2Zx.png)

### Advantages of using NestJS

*   Nest can be scalable thanks to the flexibility of JavaScript and the robustness of TypeScript
*   Detailed and well-maintained documentation
*   It has active codebase development and maintenance
*   It is open source (MIT license)
*   Code generation helps to develop applications faster
*   Has a quickly growing community
*   Follows strict design principles that do a lot of basic development activities for developers

### Disadvantages of using NestJS

*   It has Angular concepts, so for developers who don’t know Angular, it may be hard to grasp at first, even if you don’t need to know Angular before working with Nest
*   Steep learning curve
*   The community is small when compared with Express

### Who uses NestJS?

*   Adidas
*   Autodesk
*   Neoteric
*   Sanofi

### 3\. NestJS Coding

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1662174904298/8MXWsmcC6.jpeg)

### What is NestJS ?

*   NodeJS Framework
*   Architecture MVC — Model, View, Controller
*   Model — Business Layer
*   Controller — Persistent Layer
*   View — Process HTML, JSON

### Advantages NestJS + TypeScript

*   Strongly Typed Language
*   Visualization of Development Errors

### Advantages NestJS + Angular

*   Incorporates Modular Ideas and Angular Dependence Injection

### Advantages NestJS

*   COC — Convention Over Configuration
*   Files
*   Folders
*   Structures of Development
*   TypeScript
*   Scalable Architecture
*   Easy Database Integration
*   Microservices Integration
*   Support REST API, GraphQL

### NestJS Guide GitHub Repository

[**GitHub - Software-Engineering-2030/NestJS-Guide: NestJS Guide Software Engenieering**  
*A progressive Node.js framework for building efficient and scalable server-side applications. Nest framework TypeScript…*github.com](https://github.com/Software-Engineering-2030/NestJS-Guide "https://github.com/Software-Engineering-2030/NestJS-Guide")[](https://github.com/Software-Engineering-2030/NestJS-Guide)

\# sudo npm install -g @nestjs/cli

nest help

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1662174905896/shqpC8NOD.png)

```
nest new nestjs-guide
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1662174907439/pl4ujf8sH.png)

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1662174909069/pRx-ZfCXv.png)

yarn start

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1662174910457/NsbLcmrDs.png)

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1662174911963/laBVKhMv5.png)

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1662174913492/VENVNEe32.png)

### NestJS Architechture Application

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1662174914783/VkbodfQ-X.png)

*   Create an Test Controller

nest g controller test

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1662174916279/oYfcHdvbx.png)

nest g controller test

*   Create an test Service

nest g service test

*   Create an Resource

nest g resource

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1662174917642/69t96VSaE.png)

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1662174918944/HsdVzjRdF.png)

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1662174920234/klYDUNStE.png)

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1662174921877/yMEjEF6vF.png)

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1662174923404/s5UdGYcZo1.png)

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1662174924865/SYAOupAca.png)

### API REST

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1662174926304/YKODnvFNe.png)

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1662174927659/TLxcwPNfj.png)

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1662174929095/zvYw2qSn8.png)

API Resource Name

### NestJS Database Integration

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1662174930456/jGwQE086w.png)

### SQL (Sequelize)

This chapter applies only to TypeScript

> ***WARNING****In this article, you’ll learn how to create a* `*DatabaseModule*` *based on the Sequelize package from scratch using custom components. As a consequence, this technique contains a lot of overhead that you can avoid by using the dedicated, out-of-the-box* `*@nestjs/sequelize*` *package. To learn more, see* [*here*](https://docs.nestjs.com/techniques/database#sequelize-integration)*.*

[Sequelize](https://github.com/sequelize/sequelize) is a popular Object Relational Mapper (ORM) written in a vanilla JavaScript, but there is a [sequelize-typescript](https://github.com/RobinBuschmann/sequelize-typescript) TypeScript wrapper which provides a set of decorators and other extras for the base sequelize.

#### Getting started[#](https://docs.nestjs.com/recipes/sql-sequelize#getting-started)

To start the adventure with this library we have to install the following dependencies:

```
$ npm install --save sequelize sequelize-typescript mysql2  
$ npm install --save-dev @types/sequelize
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1662174931708/z61V2tjtc.png)

```
 yarn add --save sequelize sequelize-typescript sqlite3
```

```
 yarn add @nestjs/sequelize
```

```
 yarn add -D @types/sequelize
```

```
`import { Sequelize } from 'sequelize-typescript';  
import { Cat } from '../cats/cat.entity';  
  
export const databaseProviders = [  
  {  
    provide: 'SEQUELIZE',  
    useFactory: async () => {  
      const sequelize = new Sequelize({  
        dialect: 'mysql',  
        host: 'localhost',  
        port: 3306,  
        username: 'root',  
        password: 'password',  
        database: 'nest',  
      });  
      sequelize.addModels([Cat]);  
      await sequelize.sync();  
      return sequelize;  
    },  
  },  
];` 
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1662174933035/ybwiw8yyU.png)

[**Sequelize**  
*Sequelize is a promise-based Node.js ORM for Postgres, MySQL, MariaDB, SQLite and Microsoft SQL Server. It features…*sequelize.org](https://sequelize.org/ "https://sequelize.org/")[](https://sequelize.org/)

### 4\. References

*   [https://nestjs.com/](https://nestjs.com/)
*   [https://blog.logrocket.com/comparing-top-node-js-frameworks-frontend-developers/](https://blog.logrocket.com/comparing-top-node-js-frameworks-frontend-developers/)
