Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

`Connection refused` in WebStorm NPM debug configuration

Bearing in mind that I have only the loosest understanding of what a debugger is really doing, I need help setting up the WebStorm npm debug configuration for an express.js application.

Here's me so far-- I click debug with my settings as I think they should be (below):

/Users/me/.nvm/versions/node/v4.4.1/bin/node --debug=8090     
/Users/me/.nvm/versions/node/v4.4.1/lib/node_modules/npm/bin/npm-cli.js run-script start

To debug "start" script, make sure $NODE_DEBUG_OPTION string is specified as the first argument for node command you'd like to debug.
For example:
 { "start": "node $NODE_DEBUG_OPTION server.js" }
Debugger listening on port 8090
...
It has begun. Port: 3000

So at this point, the application has started up and responds to my POST to localhost:3000, but does not break on the breakpoint I set.

Looking in the Debugger>Variables pane, I see Connecting to localhost:57617, then a tooltip pops up saying "Connection refused" and the pane says Frame is not available.

I don't understand where that port number 57617 is coming from. It varies, though not according to any pattern I've yet discovered, except inasmuch as it is always different than the one I set in the --debug=X or --debug-brk=X node option.

like image 500
Ben Avatar asked May 12 '16 21:05

Ben


People also ask

How to debug a WebStorm project using Node JS V7?

Use --inspect or --inspect-brk parameter when you are using Node.js v7 for Chrome Debugging Protocol support. Otherwise, by default the debug process will use V8 Debugging Protocol. In this field. specify the package manager to use. If you choose the Project alias, WebStorm will use the default project package manager from the Node.js page.

Why is WebStorm asking me to stop the running instance?

By default, it is disabled, and when you start this configuration while another instance is still running, WebStorm suggests stopping the running instance and starting another one. This is helpful when a run configuration consumes a lot of resources and there is no good reason to run multiple instances.

How do I change the default run configuration in WebStorm?

By default, it is disabled, and WebStorm stores run configuration settings in .idea/workspace.xml. The tree view of run/debug configurations has a toolbar that helps you manage configurations available in your project as well as adjust default configurations templates. Create a run/debug configuration. Delete the selected run/debug configuration.

How do I run multiple WebStorm configurations in parallel?

If you want to run several configurations in parallel, use a compound run/debug configuration. Run File Watchers: select this option to have WebStorm apply all the currently active File Watchers. Run Remote External tool: adds a remote SSH external tool. Run Grunt task: select this option to run a Grunt task.


1 Answers

The error message is indeed very unclear. You need to adjust your npm script entry in the package.json (sadly). Found a clear description in this blog post: http://pavelpolyakov.com/2016/05/01/webstorm-npm-tasks-debug/

Your start entry should look like the following:

"scripts": {
    "start": "node $NODE_DEBUG_OPTION ./node_modules/someModule/bin/someModule.js --arguments"
}

You could also go with two entries to keep the first one DRY. Though it is not really necessary since both run just fine from command line. So just for completeness' sake:

"scripts": {
    "start": "someModule --arguments",
    "startDebug": "node $NODE_DEBUG_OPTION ./node_modules/someModule/bin/someModule.js --arguments"
}

I don't find this method particularly clean, imo that is what the npm debugger should do for you without having to manipulate source code. But it appears to be the only way (for now).

like image 65
smets.kevin Avatar answered Oct 22 '22 15:10

smets.kevin