node.js 我可以向 NPM 添加调试脚本吗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9633280/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 15:18:45  来源:igfitidea点击:

Can I add a debug script to NPM?

node.jsnpm

提问by eliocs

I have edited my package.json to customize the "start" script so it adds the --debug flag to node:

我编辑了我的 package.json 以自定义“开始”脚本,因此它将 --debug 标志添加到节点:

  "scripts": {
    "start": "node --debug server.js"
  }

Is there a way of adding new scripts for example a debug script that would do what my customized "start" is doing right now?

有没有办法添加新脚本,例如调试脚本,它可以执行我的自定义“开始”现在正在执行的操作?

I'm looking to be able to execute:

我希望能够执行:

npm debug

回答by Dan Midwood

In your package.json define the script

在你的 package.json 中定义脚本

"scripts": {
  "debug": "node --inspect server.js"
}

And then you can use npm's run-script

然后你可以使用 npm 的运行脚本

npm run-script debug

or the shorter version

或者更短的版本

npm run debug

回答by MatayoshiMariano

From the nodejs docs:

来自 nodejs文档

The legacy debugger has been deprecated as of Node 7.7.0. Please use --inspect and Inspector instead.

自 Node 7.7.0 起,旧调试器已被弃用。请改用 --inspect 和 Inspector。

So starting from Node 7.7.0v use --inspect

所以从 Node 7.7.0v 开始使用 --inspect