脚手架
$ npm i -g @nestjs/cli
$ nest new project-name 或
$ nest n my-api
$ nest g
class (alias: cl)
controller (alias: co)
decorator (alias: d)
exception (alias: e)
filter (alias: f)
gateway (alias: ga)
guard (alias: gu)
interceptor (alias: i)
middleware (alias: mi)
module (alias: mo)
pipe (alias: pi)
provider (alias: pr)
service (alias: s)
pm2 start dist/main.js --watch
# 查询进程
pm2 ls
# 查看日志
pm2 logs
tree ./src/app >tree.md
@Request() req
@Response() res
@Next() next
@Session() req.session
@Param(param?: string) req.params / req.params[param]
@Body(param?: string) req.body / req.body[param]
@Query(param?: string) req.query / req.query[param]
@Headers(param?: string) req.headers / req.headers[param]
throw new HttpException({
status: HttpStatus.FORBIDDEN,
error: 'This is a custom message',
}, 403);
throw new ForbiddenException();
@ValidatorConstraint()
export class ValDecimalArray implements ValidatorConstraintInterface {
validate(numberArr: Number[], args: ValidationArguments) {
return Array.isArray(numberArr)
&& numberArr.filter(i => typeof i === "number" && i >= 0 && i < 1).length === numberArr.length;
}
defaultMessage(args: ValidationArguments) {
return "DecimalArray is >0 <1 number array ";
}
}
@Validate(ValDecimalArray) value: number[]
玉东数据是一家专注于互联网应用开发的企业,由从业多年的技术专家组成,在应用开发、网络运维等方面有广泛的经验和实力。
技术涵盖最新的 Web、小程序、Flutter、Android、iOS等多个领域的前沿技术。
商务合作,请微信扫码联系我: