构建稳固的Node.js API

这是一个示例项目,展示了如何构建高可靠性的 Node.js API。代码中包含详细注释,解释了实现思路、库选择原因以及一些个人见解。

该 API 目前只实现了基本的用户 CRUD 功能,并包含身份验证机制。欢迎提出改进建议,将其扩展为更复杂、更实用的示例。

环境搭建

  • Node.js 版本:14.9.0 ( 使用 nvm 安装和切换版本 )
  • 运行 npm install 安装依赖
  • 使用 npm run start 启动服务器 ( 使用 nodemon 自动重启 )

在线部署

您可以使用 Gitpod 在线运行该项目。点击 Gitpod 按钮后,它会自动完成以下操作:

  • 克隆项目仓库
  • 安装依赖
  • 复制 .env.example 文件为 .env
  • 运行 npm run start

API 验证

该项目使用 Celebrate 和 ...

zip
bulletproof-nodejs-master.zip 预估大小:46个文件
folder
bulletproof-nodejs-master 文件夹
file
.env.example 324B
file
.eslintrc.js 987B
folder
src 文件夹
file
app.ts 826B
folder
services 文件夹
file
auth.ts 4KB
file
mailer.ts 1KB
folder
models 文件夹
file
user.ts 540B
folder
subscribers 文件夹
file
events.ts 91B
file
user.ts 2KB
folder
decorators 文件夹
file
eventDispatcher.ts 555B
folder
types 文件夹
folder
express 文件夹
file
index.d.ts 294B
folder
config 文件夹
file
index.ts 1KB
folder
jobs 文件夹
file
emailSequence.ts 654B
folder
interfaces 文件夹
file
IUser.ts 200B
folder
api 文件夹
file
index.ts 279B
folder
middlewares 文件夹
file
index.ts 136B
file
isAuth.ts 1KB
file
attachCurrentUser.ts 988B
folder
routes 文件夹
file
agendash.ts 442B
file
auth.ts 3KB
file
user.ts 357B
folder
loaders 文件夹
file
jobs.ts 397B
file
logger.ts 750B
file
dependencyInjector.ts 861B
file
express.ts 2KB
file
index.ts 1KB
file
events.ts 58B
file
agenda.ts 467B
file
mongoose.ts 331B
folder
.circleci 文件夹
file
config.yml 401B
file
.gitpod.yml 315B
file
.prettierrc.json 132B
file
tsconfig.json 640B
file
LICENSE 1KB
file
jest.config.js 6KB
file
Procfile 22B
file
README.md 4KB
file
nodemon.json 159B
file
.editorconfig 196B
folder
tests 文件夹
file
sample.test.ts 103B
folder
services 文件夹
folder
.gitkeep 文件夹
folder
.gitkeep 文件夹
file
.gitpod.Dockerfile 245B
file
.gitignore 193B
file
.eslintignore 9B
file
package-lock.json 385KB
file
package.json 2KB
zip 文件大小:123.97KB