Readdy Write  
0,00 €
Your View Money
Views: Count
Self 20% 0
Your Content 60% 0

Users by Links 0
u1*(Content+Views) 10% 0
Follow-Follower 0
s2*(Income) 5% 0

Count
Followers 0
Login Register as User

Cheat Sheet NestJS

15.03.2023 (👁7764)

Cheat Sheet

Install nestjs cli for nest commands

npm i -g @nestjs/cli

 

Create a nestJs Project in a new folder with app.modules, app.controllers and app.service

nest new nestjs_backend

 

Goto new project

cd nestjs_backend

 

Start as Debug Server

npm run start:dev

 

 

Embed PostgreSQL Server + typeorm

npm install --save typeorm typeorm pg

 

Embed MySQL Server

npm install --save typeorm mysql2

 

For dataset IsNotEmpty, MinLength..

npm install class-validator


Erstellen von Resource (Controller+Service+Module+CRUD)

nest g resource articles

 

Ein Bild, das Text enthält.

Automatisch generierte Beschreibung

 

 

Einzeln erstellen

Create a Controller-File (in the folder)

nest -- generate controller articles


Create a Service-File (in the folder)

nest -- generate service articles

 

 

Install Swagger

Documentation https://docs.nestjs.com/openapi/introduction

npm install --save @nestjs/swagger swagger-ui-express

 

Add swagger in start

import { NestFactory } from '@nestjs/core';

import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger';

import { AppModule } from './app.module';

 

async function bootstrap() {

  const app = await NestFactory.create(AppModule);

 

  const config = new DocumentBuilder()

    .setTitle('nestjs backend')

    .setDescription('nestjs API articles and users')

    .setVersion('1.0')

    .addTag('nestjs')

    .build();

  const document = SwaggerModule.createDocument(app, config);

  SwaggerModule.setup('api', app, document);

 

  await app.listen(3000);

}

bootstrap();

 

 

nest generate resource articles

Ein Bild, das Text enthält.

Automatisch generierte Beschreibung

> REST API

  GraphQL (code first)

  GraphQL (schema first)

  Microservice (non-HTTP)

  WebSockets

 

 

Documentation at:
https://docs.nestjs.com/first-steps

Ein Bild, das Text enthält.

Automatisch generierte Beschreibung