Debug node modules in nwjs

偶尔善良 提交于 2019-12-12 03:33:19

问题


We're developing an application based on node webkit (nwjs) that is a mix of node modules and angular code. A lot of business logic has been moved to the node modules and I haven't found a way to debug that code in the running application.

Debugging with devtools doesn't seem to work, and that's a known limitation or bug (Debugging with devtools). I even tried to require node-monkey from one of the scripts, hoping to be able to open some sort of backdoor ;) - didn't work unfortunately.

So is there any other way or trick to (remote) debug the code?


回答1:


I'm using the Chrome Debugger Extension to debug my node modules in my nwjs app.

Here's the config in launch.json:

{
    "name": "Launch nwjs",
    "type": "chrome",
    "request": "launch",
    "webRoot": "${workspaceRoot}/src", //where you put your .js files
    "runtimeExecutable": "nw"
    "runtimeArgs": [
        "${workspaceRoot}",
        "--chrome-remote-port=9222"
    ],
    "sourceMaps": false,
    "diagnosticLogging": true,
    "port": 9222
},

I had to change some files from VS Code since the editor ignores URL's that starts with chrome-extension:// by default and the Nwjs runs your app under this protocol...

This Issue on GitHub helped me alot.

https://github.com/nwjs/nw.js/issues/4919




回答2:


Have a look at node-inspector

You should be able to start your application with node-debug instead of node and it will open chrome devtools looking inside your app.

You can also use this to debug a remote server.

You can then add breakpoints, watch variables, etc as you would if you were debugging a web application.



来源:https://stackoverflow.com/questions/31310714/debug-node-modules-in-nwjs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!