简体   繁体   English

使用supervisor在debug中运行node.js应用程序

[英]Run node.js application in debug with supervisor

I am using supervisor to auto-reload my node.js, eg 我正在使用supervisor自动重新加载我的node.js,例如

supervisor -w . app.js

However I can't work out how to get supervisor to run the node.js process in debug, eg the equivalent to 但是我无法弄清楚如何让supervisor在debug中运行node.js进程,例如相当于

node --debug app.coffee

Anyone got any ideas? 有人有任何想法吗?

This also works (and you don't need a separate bash script): 这也有效(并且您不需要单独的bash脚本):

supervisor -- --debug app.js
supervisor -- --debug=7070 app.js

This solution will work for *nix: 此解决方案适用于* nix:

Go to /usr/local/bin or any other directory in your $PATH 转到/usr/local/bin或$ PATH中的任何其他目录

$ cd /usr/local/bin

Create an executable script (say, node-debug) with the following contents 使用以下内容创建可执行脚本(例如,node-debug)

#!/bin/bash
node --debug $@

To make it executable: 使其可执行:

$ sudo chmod 777 /usr/local/bin/node-debug

Now you can run supervisor like this: 现在你可以像这样运行主管:

$ supervisor -x node-debug script.js

PS: To round it up: PS:围捕它:

su
echo '#!/bin/bash
node --debug $@' > /usr/local/bin/node-debug
chmod 777 /usr/local/bin/node-debug

From the CoffeeScript site : CoffeeScript网站

--nodejs The node executable has some useful options you can set, such as --debug, --debug-brk and --max-stack-size. --nodejs节点可执行文件有一些你可以设置的有用选项,例如--debug, - debug-brk和--max-stack-size。 Use this flag to forward options directly to Node.js. 使用此标志将选项直接转发到Node.js.

I tried this and it worked: 我试过这个并且它有效:

supervisor -- --nodejs --debug app.coffee 主管 - --nodejs --debug app.coffee

You can add other arguments like this: 您可以添加其他参数,如下所示:

supervisor -w . 主管-w。 -n error -- --nodejs --debug app.coffee -n error - --nodejs --debug app.coffee

node-dev 节点开发

node-dev on Github Github上的node-dev

"All arguments are passed on to the child-process. node-dev --debug server.js will debug your application, not the supervisor itself." “所有参数都传递给子进程.node-dev --debug server.js将调试你的应用程序,而不是主管本身。”

Create a "test.js" node.js script in $HOME/nodetest 在$ HOME / nodetest中创建一个“test.js”node.js脚本

First terminal (run node in debug mode, debug will listen on the port 5858, node-dev will reload changed files): 第一个终端(在调试模式下运行节点,调试将侦听端口5858,node-dev将重新加载已更改的文件):

    cd $HOME/nodetest
    npm install node-dev
    node_modules/.bin/node-dev --debug test.js

Second terminal (start web inspector for a WebKit based browser, inspector connects to the port 5858 of the debugger and listens on the port 8080): 第二个终端(启动基于WebKit的浏览器的Web检查器,检查器连接到调试器的端口5858并侦听端口8080):

    cd $HOME/nodetest
    npm install node-inspector
    node_modules/.bin/node-inspector

Open this URL in a WebKit based browser (Chrome, Safari, etc.): 在基于WebKit的浏览器(Chrome,Safari等)中打开此URL:

    http://0.0.0.0:8080/debug?port=5858

Click on "Scripts" and set breakpoints in your code. 单击“脚本”并在代码中设置断点。

Use the -x flag as documented on the node-supervisor github page 使用node-supervisor github页面上记录的-x标志

supervisor -w . -x 'node --debug' app.js

but that won't work with coffeescript so you have to use 但这对coffeescript无效,所以你必须使用

supervisor -w . -x 'coffee --debug' app.js

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM