NestJS RESTful APIs 示例项目教程

NestJS RESTful APIs 示例项目教程

nestjs-rest-sampleNestJS RESTful APIs Sample项目地址:https://gitcode.com/gh_mirrors/ne/nestjs-rest-sample

1. 项目的目录结构及介绍

nestjs-rest-sample/
├── docs/
│   └── guide.md
├── src/
│   ├── app.module.ts
│   ├── main.ts
│   ├── ...
├── test/
├── .eslintrc.js
├── .gitignore
├── .mergify.yml
├── .prettierrc
├── Dockerfile
├── LICENSE
├── README.md
├── codecov.yml
├── commitlint.config.js
├── docker-compose.yml
├── nest-cli.json
├── package-lock.json
├── package.json
├── tsconfig.build.json
└── tsconfig.json
  • docs/: 包含项目文档,如 guide.md
  • src/: 包含项目的源代码,如 app.module.tsmain.ts
  • test/: 包含项目的测试代码。
  • .eslintrc.js: ESLint 配置文件。
  • .gitignore: Git 忽略文件配置。
  • .mergify.yml: Mergify 配置文件。
  • .prettierrc: Prettier 配置文件。
  • Dockerfile: Docker 配置文件。
  • LICENSE: 项目许可证。
  • README.md: 项目说明文档。
  • codecov.yml: Codecov 配置文件。
  • commitlint.config.js: Commitlint 配置文件。
  • docker-compose.yml: Docker Compose 配置文件。
  • nest-cli.json: NestJS CLI 配置文件。
  • package-lock.json: npm 锁定文件。
  • package.json: npm 配置文件。
  • tsconfig.build.json: TypeScript 构建配置文件。
  • tsconfig.json: TypeScript 配置文件。

2. 项目的启动文件介绍

src/main.ts

import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';

async function bootstrap() {
  const app = await NestFactory.create(AppModule);
  await app.listen(3000);
}
bootstrap();
  • main.ts 是 NestJS 项目的入口文件,负责启动应用程序。
  • 使用 NestFactory.create 方法创建一个 Nest 应用实例。
  • 调用 app.listen 方法在端口 3000 上启动应用。

3. 项目的配置文件介绍

nest-cli.json

{
  "collection": "@nestjs/schematics",
  "sourceRoot": "src"
}
  • nest-cli.json 是 NestJS CLI 的配置文件。
  • collection 指定使用的 NestJS 脚手架集合。
  • sourceRoot 指定源代码的根目录。

package.json

{
  "name": "nestjs-rest-sample",
  "version": "1.0.0",
  "description": "NestJS RESTful APIs sample project",
  "scripts": {
    "start": "nest start",
    "build": "nest build",
    "test": "jest"
  },
  "dependencies": {
    "@nestjs/common": "^8.0.0",
    "@nestjs/core": "^8.0.0",
    "@nestjs/platform-express": "^8.0.0",
    "reflect-metadata": "^0.1.13",
    "typescript": "^4.3.5"
  },
  "devDependencies": {
    "@nestjs/testing": "^8.0.0",
    "jest": "^27.0.6"
  }
}
  • package.json 是 npm 配置文件,包含项目的基本信息、脚本命令和依赖项。
  • scripts 定义了常用的脚本命令,如 startbuildtest
  • dependenciesdevDependencies 分别列出了项目运行时和开发时的依赖项。

tsconfig.json

{
  "compilerOptions": {
    "module": "commonjs",
    "declaration":

nestjs-rest-sampleNestJS RESTful APIs Sample项目地址:https://gitcode.com/gh_mirrors/ne/nestjs-rest-sample

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

周琰策Scott

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值