前言
基于本人在现在公司的Node微服务实践, 不断维护升级着一个Node Restful API种子项目, 特此共享出来以供借鉴和讨论. 项目中几乎所有的东西都使用了node/javascript及相应模块的最新功能, 语法, 和实践. 如果你需要的是一个大而全的框架, eggjs应该是很好的选择. 如果你动手能力强, 追求自由灵活, 并且不排斥express, 那可以试试采用我这个项目.
项目github仓库地址, 欢迎star: https://github.com/xiaozhongliu/node-api-seed 下面先贴一下我在github上对项目的综合描述, 完了在下一篇帖子会一一展示项目的各个方面, 至于怎么实现的可以看源码, 相信你会喜欢上我干净简洁, 层次清晰, 与时俱进的代码风格的😅.
综述
Techs involved:
Aspect | Tech |
---|---|
web fx | express |
task | node-schedule |
db postgres | sequelize |
db mongodb | mongoose |
memcache | node_redis |
http client | axios |
logger | log4js-node |
mailer | nodemailer |
jwt auth | jsonwebtoken |
validation | express-validator |
async flow | async/await of ES7 |
test fx | jest |
dashboard | express-status-monitor |
log auth | http-auth |
js checker | eslint |
proc mana | pm2 |
Other features offering:
Api access control via ts & token. Elaborate api request log into files. Flexible declarative request validation. Request log online view behind http auth. Server status monitor dashboard behind http auth. Ready made api samples with jwt and latest js features. Centralized system level config & messages management. Elaborate api test: test samples & ready made debug config. Reasonable multi-env config merging mechanism. Definite DRY, SRP, AOP, ES6/ES7, OCD, etc.
Npm commands usage:
cnpm i # install all packages for dev env
npm t # run api tests written on the basis of jest
npm start # run service in dev env, or hit F5 to debug in vsc
npm run pm2start # host via pm2 in prod env
npm run pm2startqa # host via pm2 in qa env
npm run pm2starttest # host via pm2 in test env
npm run pm2restart # restart hosted service in prod env
npm run pm2restartqa # restart hosted service in qa env
npm run pm2restarttest # restart hosted service in test env
npm run pm2stop # hang up hosted service
npm run pm2delete # remove hosted service
周末整理好会发出第二篇帖子, 关于这个项目的说明书.