# 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/v1662833247887/Ro98bzUaS.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/v1662833249416/Y95rF0-yo.jpeg)

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

### Types of NodeJS Frameworks

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

NodeJS Frameworks

### Some statistics

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1662833253398/tAxEKZAbS.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/v1662833254751/hCzU3B9jB.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/v1662833256379/11HJftYoI.png)

```
nest new nestjs-guide
```

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

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

yarn start

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1662833261018/3_bkCN0cY.png)

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

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1662833264039/3bBljB0RLx.png)

### NestJS Architechture Application

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

*   Create an Test Controller

nest g controller test

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1662833266869/z3J55d_7Q.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/v1662833268283/scSQCRhwqFp.png)

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1662833269496/4ewNsgOSh8.png)

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

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1662833273188/6-M6D8e26.png)

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

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

### API REST

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

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

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1662833281677/0AUOFJOUB.png)

API Resource Name

### NestJS Database Integration

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1662833283043/dd2C4nDz1.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/v1662833284321/DNXN-TxKS.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/v1662833285709/ZfXN0ka0h.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/)
