yitala
yitala
NodeJS在web领域常常作为服务器运行。NodeJS可以像其他服务器一样进行数据库操作、逻辑运算、HTTP和websocket通信、文件读写、模板渲染等等许多功能。在美柚NodeJS更多的用来做中间层,用来做API的请求结合模板引擎进行服务端渲染,还有一些轻微的逻辑处理。本文对比最佳实践例子与反面例子,系统阐述NodeJS日志的解决方案。 ## 1. 划分不同的错误类型 要用使用NodeJS环境自带的Error对象进行抛错,它含有错误的堆栈信息和其他有用属性。根据业务需要设计不同类型的Error,根据场景选择正确的Error输出。 ### 正确使用 ```javascript app.get('/api', (req, res, next) => { Http.fetch(url) .then(resp => { throw new Error('错误信息') }) .catch(err => next(err)) }) ```  堆栈信息将被收集,方便开发调试,也用于记录生产错误信息。 ###...
``` Document .spin { position: absolute; top:50%; left: 50%; transform: translate(-50%, -50%); animation: rotate-music 10s infinite linear; } .no-animation { -webkit-animation: none !important; -moz-animation: none !important; animation: none !important; }...
log shows: NFO connecting 127.0.0.1:3306. It never callback, stuck forever. ENV: deno: 1.0.0 mysql: 8.0
