How do I debug a nodejs webserver that runs from a gulp task?

Hey everyone,
Just started using WebStorm and I love it so far. But I am having trouble getting the debugger to work with our current project.

We have a nodejs website that uses gulp to start the server.

Normally I start the webserver using the command "npm run dev"

package.json:

  "scripts": {     "dev": "NODE_ENV=development gulp dev"   }


gulpfile.js
gulp.task('dev', function (done) {
  runSequence('build', ['watch', 'server'], done);
});


The gulp task "build" compiles the sass to css and does some other work.
The "watch" task runs gulp-livereload watches the javascript/images/css for changes and does a reload.
The "server" task starts the actual nodejs webserver in nodemon.

I am having trouble getting this gulp task "dev" to run within WebStorm and also allow me to debug the nodejs server (not the gulp task).

Things Ive tried:
1. Created a Nodejs configuration file. Cannot run the gulp task from this config so this is a no go.
2. Created a Gulp.js configuration to run the "dev" task. This lets me sucessfully run the nodejs server from within Webstorm but I cannot debug the server. I can only debug the gulp file. No go.
3. Updated the "server" gulp task to include the argument --debug=4001. Created a Gulp.js config to run the "dev" task. Then create a Nodejs Remote Debug config (listen to port 4001). Set the gulp.js config as a Before Launch config for the Nodejs Remote Debug config. Also a no go. It looks like the Before Launch scripts need to finish before the main config can run.

I know I can simply run the gulp task in a terminal and then use the Nodejs Remote Debug config to listen to the debug port. But I would like the console window to be inside WebStorm.

Does anyone have any suggestions?

1 comment
Comment actions Permalink

Well, the easiest way to do what you want is using 2 configurations (Gulp.js and Nodejs Remote Debug) and running them in WebStorm one after another (select Gulp.js, run, then select Nodejs Remote Debug and run it). Adding Gulp.js to 'before launch' section of Nodejs Remote Debug run  configuration won't work, as the main process (remote debugger) will wait  for return code from the process run in 'before launch' (and remote debugging won't start untill Gulp process is terminated). This is the way  'before launch' is designed - it's supposed to be used to run some sort  of pre-processing before running the main process.

-3

Please sign in to leave a comment.