前言
基於本人在現在公司的Node微服務實踐, 不斷維護升級著一個Node Restful API種子專案, 特此共享出來以供借鑑和討論. 專案中幾乎所有的東西都使用了node/javascript及相應模組的最新功能, 語法, 和實踐.
如果你需要的是一個大而全的框架, eggjs應該是很好的選擇. 如果你動手能力強, 追求自由靈活, 並且不排斥express, 那可以試試採用我這個專案.
專案github倉庫地址, 歡迎star: github.com/xiaozhongli…
下面先貼一下我在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 |
dashboard | express-status-monitor |
jwt auth | jsonwebtoken |
validation | express-validator |
async flow | async/await of ES7 |
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.
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 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
複製程式碼