node.js - 如何在终端node.js中显示有错误的整行
解决方案
假设您将有一个 try/catch 片段,您可以使用以下
var stack = new Error().stack
console.log( stack ) //will print file and line plus the stack
或者
console.trace()
同样,node.js 默认会打印错误的堆栈跟踪。您可以查看所有这些行,直到找到您制作的源文件 - 这是旧样式,但在找到错误的确切来源时它不会失败。例如
Error: Something unexpected has occurred.
at main (c:\Users\Me\Documents\MyApp\app.js:9:15) //this file would be yours
at Object. (c:\Users\Me\Documents\MyApp\app.js:17:1)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Function.Module.runMain (module.js:501:10)
at startup (node.js:129:16)
at node.js:814:3
我希望这有帮助
推荐阅读
- sendgrid - 到 Gmail 的 Sendgrid 电子邮件路由
- go - 来自 Goroutine 通道的随机结果,该通道接收指向底层对象的指针
- javascript - 从 php 调用函数时重置 Javascript 全局变量
- python-3.x - Reshaping nested numpy array,
- reactjs - reactjs 应用程序 - 无法显示我的 hello world
- python - 如何将图像的总和除以opencv中的图像总数
- python - 更多pythonic方式来编辑列值 - python pandas
- javascript - 如何在打字稿地图方法中使用javascript查找表?
- javascript - 多么不明白这段代码是什么:Javascript
- c# - 设置类实例中的变量后运行类初始化函数的优雅解决方案