How to Debug a multi-threaded node-webkit application

All,

I have an application where when my index.html is loaded by node-webkit it executes a run-server.js file:

index.html
    loadScript("run-server.js") - This will create a script element in the document set to the contents of the .js file given.

run-server.js
    global.serverProcess = ch.fork('server', [], {

      execPath: execPath,
      env: process.env,
      execArgv: ['--debug-brk'],
  });


The run-server.js file uses the child_process fork function to create a new process for my server which listens for commands to be sent to localhost port 8100.

What I'm having an issue with is that I can setup a node-webkit configuration that allows me to debug my main application, includeing run-server.js with no issue.  But I cannot seem to connect the debugger to the child process that is being created in run-server.js.  

I saw this post (https://devnet.jetbrains.com/message/5507221) but it looks like it is talking more about how to debug a node process and not node-webkit.  The difference I think being that the run-server.js is loaded independently in the index.html.

Any insights you have would be a appreciated.  I can share more code if needed, I just didn't want to overwhelm people with too much :

Thanks,
Chase

1 comment
Comment actions Permalink

All,

I have an update on this after restructuring my code but I'll still having issues I could use advice on.

My code now does the following:

Index.html:
    Load a script called run-server.js

run-server.js
    if (!global.embeddedIpgServer) {

    global.embeddedIpgServer = require("./embeddedServer/server");
  }


embeddedServer/server
    var USB2ANY = require('./usb2any');

I'm trying to set a breakpoint in the usb2any file to debug.  It seems that by changing this code to be a node module that is loaded with a require instead of being a script that was directly loaded by index.html in the past I have lost the ability for Webstorm to set and hit breakpoints in the code.  I can use the node-webkit devtools to set and debug the code but this is less than ideal

So is there a way when running a node-webkit debug configuration to connect the debugger to the code loaded in the node.js context?

Thanks,
Chase

0

Please sign in to leave a comment.