Node.js最佳实践
Node.js最佳实践
使用全局变量
| 1 | global.CONSTANTS = constants; | 
| 1 | node -r global test.js | 
全局临时目录.temp & WORKSPACE
| 1 | const mkdirp = require('mkdirp'); | 
二级缓存
lru-cache + redis
co-catch-next | promise.catch-next
| 1 | co(function* () { | 
| 1 | Q.fcall(promisedStep1) | 
异常处理 catch-next & uncaughtException & domain
| 1 | app.use(function(err, req, req, next) { | 
| 1 | process.on('uncaughtException', (err) => { | 
| 1 | var domain = require('domain'); | 
退出程序
| 1 | process.on('SIGINT', () => { | 
pm2.yml配置
| 1 | # pm2.yml | 
参考
    
    本站采用「署名 4.0 国际」进行许可。