Skip to content

Instantly share code, notes, and snippets.

Last active October 14, 2023 19:46
  • Star 37 You must be signed in to star a gist
  • Fork 9 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Nest.js Cheatsheet

Nest.js Cheatsheet

Nest CLI

  • npm i -g @nestjs/cli


  • yarn add class-validator class-transformer
  • yarn add @nestjs/mapped-types


  • npm run start:dev / yarn start:dev
  • nest generate controller / nest g co
  • nest generate service / nest g s
  • nest generate modue <name> / nest g mo
  • nest g class address/dto/create-address.dto --no-spec


  • @Injectable(): Make a resource injectable via DI
  • @Controller('route'):
  • @Get(), @Post('user/:id/update')
  • @HttpCode(HttpStatus.GONE): Change http status
  • @Param() params: All url params, @Param('id'): Only id param
  • @Query() params: All url params, @Query('id'): Only id param
  • @Body() body: All body values, @Body('id'): Only id value
  • @Res() response: Response object from express
  • @IsNumber(), @IsString(): Validations


  • import { Body, Controller, Get, Param, Post } from '@nestjs/common';
  • import { IsNumber, IsString } from 'class-validator'; - Validation
import { IsNumber, IsString } from 'class-validator';
export class CreateAddressDto {
readonly cep: number;
readonly address: string;
readonly city: string;
readonly state: string;
import { PartialType } from "@nestjs/mapped-types";
import { CreateAddressDto } from "./create-address.dto";
export class UpdateAddressDto extends PartialType(CreateAddressDto) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment