Cheat Sheet
Install
nestjs cli for nest commands
Create a
nestJs Project in a new folder with app.modules, app.controllers and app.service
Goto new
project
Start as
Debug Server
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)
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
|
> REST
API
GraphQL (code first)
GraphQL (schema first)
Microservice (non-HTTP)
WebSockets
Documentation at:
https://docs.nestjs.com/first-steps