javascript 与 nodemon 一起运行 node-inspector 吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25798050/
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
Running node-inspector alongside nodemon?
提问by Jamie Hutber
I'm currently using node along with nodemon. Then I got to thinking it might be sometimes nice to use an inspector with node so have started using node-inspector
我目前正在使用 node 和nodemon。然后我开始认为有时将检查器与节点一起使用可能会很好,所以我开始使用节点检查器
However, is it possible to run both at the same time?
但是,是否可以同时运行两者?
Normally to run nodemon I would use:
通常运行 nodemon 我会使用:
nodemon server.js
//and similarly
node-debug server.js
I have also tried:
我也试过:
nodemon --debug http.js
But sadly this didn't work either.
但遗憾的是,这也不起作用。
But both together!?
但是两个一起!?
采纳答案by Paul
You would start your server with nodemon --debug server.js
and then you'll need to run node-inspector in a separate terminal window unless you push nodemon to the background.
您将启动服务器,nodemon --debug server.js
然后您需要在单独的终端窗口中运行 node-inspector,除非您将 nodemon 推送到后台。
回答by rpaskett
If you want to run them as one command this works for me: node-inspector & nodemon --debug app.js
(replacing app.js with the name of your script). If things get all mucked up you will occasionally have to kill node-inspector manually, but running the command this way gives you the option of running rs
to restart nodemon manually if needed. HTH
如果您想将它们作为一个命令运行,这对我node-inspector & nodemon --debug app.js
有用:(用您的脚本名称替换 app.js)。如果事情变得一团糟,您有时必须手动rs
终止node-inspector,但是以这种方式运行命令可以让您选择在需要时手动重新启动 nodemon。HTH
回答by olive_tree
For those that want an OS-independent solution and no hacks for windows, etc.
对于那些想要独立于操作系统的解决方案并且没有针对 Windows 等的黑客的人。
You can use npm-run-all which is a CLI tool that allows running multiple npm scripts in parallel or sequentially. So you'd set your package.json as so:
您可以使用 npm-run-all,它是一个 CLI 工具,允许并行或顺序运行多个 npm 脚本。因此,您可以将 package.json 设置为:
"scripts": {
"start": "npm-run-all --parallel lint start:debug start:server",
"lint": "eslint . --ext .js",
"start:debug": "node-debug server.js",
"start:server": "nodemon server.js"
}
And then from CLI, you do: npm start
然后从 CLI,你做: npm start
Caveat: from my experience running nodemon and node-debug together leads to weird node-inspector behaviors sometimes. So i've since opted to remove nodemon from my scripts when debugging and relying on node-inspectors save-live-edit feature to change files on the fly.
警告:根据我的经验,同时运行 nodemon 和 node-debug 有时会导致奇怪的节点检查器行为。因此,我选择在调试时从我的脚本中删除 nodemon,并依靠 node-inspectors save-live-edit 功能来动态更改文件。
回答by Erick Wendel
{
"scripts": {
"dev": "npx nodemon --exec \"node --inspect --debug-port=0.0.0.0 src/index.js\""
}
}
回答by HMR
I could not get nodemon to play nice with node-inspector. After one change it would restart but after that no more. Maybe it is because I am using docker containers.
我无法让 nodemon 与 node-inspector 一起玩。一次更改后,它会重新启动,但之后就不会了。也许是因为我正在使用 docker 容器。
The easiest way to reload the application is to let node-inspector do it (I know this is not an answer to having both run but it worked for me).
重新加载应用程序的最简单方法是让节点检查器执行它(我知道这不是同时运行的答案,但它对我有用)。
Start your application in the following way:
通过以下方式启动您的应用程序:
node-inspector --save-live-edit & \
node --debug /app/server.js
回答by mattbell87
As I'm running on Linux I wrote a bash scriptbased from rpaskett's answerso that you don't need to remember that awkward command every time.
当我在 Linux 上运行时,我根据rpaskett 的回答编写了一个 bash 脚本,这样您就不必每次都记住那个笨拙的命令。
However I noticed in a comment you're running Windows. Here are some options you have:
但是我在评论中注意到您正在运行 Windows。以下是您的一些选择:
You could convert the bash script to Windows batchand save it as C:\Windows\System32\node-DEV.bat
. I did it and it works on my Windows PC:
您可以将 bash 脚本转换为Windows 批处理并将其另存为C:\Windows\System32\node-DEV.bat
. 我做到了,它可以在我的 Windows PC 上运行:
@echo off
echo Starting DEV environment for %1
start node-inspector
nodemon --debug %1
Then you should be able to run node-DEV server.js
.
然后你应该能够运行node-DEV server.js
.
Another option; you could run something like nodedevwhich was written in Node.js thus platform independent, although it looks like it hasn't been updated in a while.
另外一个选择; 你可以运行像nodedev这样的东西,它是用 Node.js 编写的,因此是平台独立的,尽管它看起来已经有一段时间没有更新了。
Or you could even run the bash script within a Cygwin environment if you had one handy.
或者,您甚至可以在 Cygwin 环境中运行 bash 脚本,如果您有手的话。
回答by Samirillian
A hacky fix for Windows users running a bash shell:
一个针对运行 bash shell 的 Windows 用户的hacky 修复:
First, add node-inspector to your Path.(You can find where npm is installing packages with npm list -g
)
首先,将节点检查器添加到您的路径。(您可以使用 找到 npm 安装软件包的位置npm list -g
)
Then use this command in bash, or add it to your npm scripts:
然后在 bash 中使用此命令,或将其添加到您的 npm 脚本中:
START /B node-inspector && nodemon --debug server.js
START /B
being the windows command to run in the background.
START /B
是在后台运行的windows命令。
回答by LordZero
You must be install node-inspector and nodemon using:
您必须使用以下命令安装 node-inspector 和 nodemon:
npm install -g nodemon
npm install -g node-inspector
To run in Windows, make a new .bat file and add the folowing lines:
要在 Windows 中运行,请创建一个新的 .bat 文件并添加以下行:
@echo off
echo Starting developer enviroment of the file %1
start nodemon --debug-brk %1
node-debug %1
And run:
并运行:
node_desarrollo.bat "name of the file to run.js"
node_desarrollo.bat "要运行的文件名.js"
If ran with a error:
如果运行出错:
Error: listen EADDRINUSE :::5858
at Object.exports._errnoException (util.js:855:11)
at exports._exceptionWithHostPort (util.js:878:20)
at Agent.Server._listen2 (net.js:1237:14)
at listen (net.js:1273:10)
at Agent.Server.listen (net.js:1369:5)
at Object.start (_debug_agent.js:21:9)
at startup (node.js:72:9)
at node.js:980:3
Its normal because the node-inspector need to open that port to connect but because the nodemon --debug-brk %1
was opened the 5858 port its cannot open and show the EADDRINUSE :::5858
error, note that the flag --debug-brk
of nodemon it's necessary to make a breakpoint on the first line. Try modifying the file.js after run the .bat and look the changes reflected on the debugger. This debugger reboots and show the changes done in the file.js. Happy coding JS!!!
这很正常,因为节点检查器需要打开该端口才能连接,但是因为nodemon --debug-brk %1
打开了 5858 端口,它无法打开并显示EADDRINUSE :::5858
错误,注意--debug-brk
nodemon的标志有必要在第一行做一个断点。运行 .bat 后尝试修改 file.js 并查看调试器上反映的更改。此调试器重新启动并显示在 file.js 中所做的更改。快乐编码 JS !!!