npm tasks debug in WebStorm

Continuing the “debug with the WebStorm” posts series. Previously I have shared my experience of having the Node.js remote debugging in WebStorm working. Today – I’m going to share with you my findings of how to make the debug of the npm task.

My goal was to debug the lab tests, which I use to test my hapi application.

Before I have started, the “scripts” part of my package.json file looked the next way:

I’ve tried to add the “Run/Debug Configuration” to the WebStorm, but when running it – nothing was happening. The tests were executed, however the application was not stopped on the debug points.

npm tasks debug WebStorm

npm tasks debug WebStorm

After some time I have figured out the correct formula, which I want to share with you, so you spend less time doing that. The key thing is your package.json file, here how it should look like:

There are three key factors:

  1. The task which you want to debug should be run by node, not by any other global program
  2. You need to place the $NODE_DEBUG_OPTION placeholder to the npm task, WebStorm will put there the debug configuration parameter
  3. If you haven’t done any additional configuration, WebStorm would not know where all the “global” programs are located. So you need to correctly point the source, which will be executed by your node instance. In my example I’ve stated the local version of lab.

Hope that saved someones time!