nestjs 开发手册
安装
1 | npm i -g @nestjs/cli |
创建项目
1 | nest new <project-name> |
nestjs 开发依赖
orm - prisma
1 | pnpm add prisma-binding @prisma/client |
1 | pnpm add -D prisma |
mock 数据
1 | pnpm add mockjs |
1 | pnpm add -D @types/mockjs |
配置文件
1 | pnpm add @nestjs/config |
校验
1 | pnpm add class-validator class-transformer |
密码加密
bcrypt 依赖 python 环境
1 | pnpm add bcrypt |
或者下载 bcryptjs
1 | pnpm add bcryptjs |
1 | pnpm add -D @types/bcryptjs |
bcrypt 使用
使用 bcrypt 加密密码
1 | import { hashSync } from "bcryptjs" |
jwt
1 | pnpm add @nestjs/jwt |
1 | SECRET = 22222 |
1 | import {JwtModule} from '@nestjs/jwt' |
passport 验证
安装依赖
1 | pnpm add @nestjs/passport passport passport-local passport-jwt |
1 | pnpm add -D @types/passport @types/passport-local @types/passport-jwt |
使用
进行登录时的校验并颁发 token
1 | import { Strategy, IStrategyOptions } from "passport-local" |
1 | import { Strategy, StrategyOptions, ExtractJwt } from "passport-jwt" |
1 | export class LoginDto { |
1 | import { Module } from "@nestjs/common" |
1 | import { Post, UseGuards } from "@nestjs/common" |
token 颁发
1 |
日期处理
1 | pnpm add dayjs |
swagger 集成
1 | pnpm add |
1 | pnpm add prisma-binding @prisma/client mockjs @nestjs/config class-validator class-transformer argon2 @nestjs/passport passport passport-local @nestjs/jwt passport-jwt lodash multer dayjs express redis @nestjs/throttler |
1 | pnpm add -D prisma typescript @types/node @types/mockjs @nestjs/mapped-types @types/passport-local @types/passport-jwt @types/express @types/lodash @types/multer @types/node |