New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I use node-inspector with gulp-nodemon ? #85

Closed
misterfresh opened this Issue Aug 12, 2015 · 13 comments

Comments

Projects
None yet
10 participants
@misterfresh

misterfresh commented Aug 12, 2015

I'm using gulp nodemon with browser-sync and it's working great.
Now I'd like to set it up so that when I write a "debugger;" statement in my code, it will open node inspector on live reload.
How can I do that?
Thanks

@JacksonGariety

This comment has been minimized.

Show comment
Hide comment
@JacksonGariety

JacksonGariety Aug 21, 2015

Owner

@misterfresh have you tried starting gulp-nodemon with debug: true as an element of the config object?

Owner

JacksonGariety commented Aug 21, 2015

@misterfresh have you tried starting gulp-nodemon with debug: true as an element of the config object?

@JacksonGariety

This comment has been minimized.

Show comment
Hide comment
@JacksonGariety

JacksonGariety Aug 21, 2015

Owner

@misterfresh if that doesn't work, try calling nodemon directly from the console and passing the --debug flag. If that work than that flag needs to be added to the config.

Owner

JacksonGariety commented Aug 21, 2015

@misterfresh if that doesn't work, try calling nodemon directly from the console and passing the --debug flag. If that work than that flag needs to be added to the config.

@beebase

This comment has been minimized.

Show comment
Hide comment
@beebase

beebase Aug 31, 2015

fyi:
Executing 'nodemon --debug server.js' in a terminal triggers node-inspector.
However, when adding it as an elem in the config object, node-inspector won't kick in.

image

beebase commented Aug 31, 2015

fyi:
Executing 'nodemon --debug server.js' in a terminal triggers node-inspector.
However, when adding it as an elem in the config object, node-inspector won't kick in.

image

@goncaloneves

This comment has been minimized.

Show comment
Hide comment
@goncaloneves

goncaloneves Sep 10, 2015

I found a solution on the config object using exec parameter that works fine, even with lint task on restart event:

/** Create debug Gulp task that runs server.js through nodemon with inspector and debug flag */
gulp.task('debug', function() {
  nodemon({
    exec: 'node-inspector & node --debug',
    ext: 'js',
    ignore: ['.idea/*', 'node_modules/*'],
    script: 'server.js',
    tasks: ['lint'],
    verbose: true
  }).on('start', ['']);
});

@beebase the reason why debug flag on the config object doesn't work is because nodemon doesn't have that attribute. The only way is executing through CLI or exec / execMap.

goncaloneves commented Sep 10, 2015

I found a solution on the config object using exec parameter that works fine, even with lint task on restart event:

/** Create debug Gulp task that runs server.js through nodemon with inspector and debug flag */
gulp.task('debug', function() {
  nodemon({
    exec: 'node-inspector & node --debug',
    ext: 'js',
    ignore: ['.idea/*', 'node_modules/*'],
    script: 'server.js',
    tasks: ['lint'],
    verbose: true
  }).on('start', ['']);
});

@beebase the reason why debug flag on the config object doesn't work is because nodemon doesn't have that attribute. The only way is executing through CLI or exec / execMap.

@ionutzp

This comment has been minimized.

Show comment
Hide comment
@ionutzp

ionutzp Sep 11, 2015

@goncaloneves the exec did the trick thanks, tried it earlier with execMap and it couldn't get it to work

ionutzp commented Sep 11, 2015

@goncaloneves the exec did the trick thanks, tried it earlier with execMap and it couldn't get it to work

@goncaloneves

This comment has been minimized.

Show comment
Hide comment
@goncaloneves

goncaloneves Sep 11, 2015

@ionutzp: for future reference, try this:

gulp.task('debug', function() {
  nodemon({
    execMap: {
      js: 'node-inspector & node --debug'
    },
    ext: 'js',
    ignore: ['.idea/*', 'node_modules/*'],
    script: 'server.js',
    tasks: ['lint'],
    verbose: true
  }).on('start', ['']);
});

goncaloneves commented Sep 11, 2015

@ionutzp: for future reference, try this:

gulp.task('debug', function() {
  nodemon({
    execMap: {
      js: 'node-inspector & node --debug'
    },
    ext: 'js',
    ignore: ['.idea/*', 'node_modules/*'],
    script: 'server.js',
    tasks: ['lint'],
    verbose: true
  }).on('start', ['']);
});
@cudasteve

This comment has been minimized.

Show comment
Hide comment
@cudasteve

cudasteve Nov 3, 2015

Wish I would have found this thread a while back. In case it helps anyone in the future, here's an alternative solution I came up with that uses the nodeArgs option if you need a little more control over node-inspector or want to have it available as its own task.

var args = require('yargs').argv;
var nodeInspector = request('gulp-node-inspector');

gulp.task('inspect', function () {
    gulp.src([]).pipe(nodeInspector({  // You'll need to tweak these settings per your setup
        debugPort: 5859,
        webHost: '0.0.0.0',
        webPort: '8085',
        preload: false
    }));
});

gulp.task('start', (args.debug) ? ['inspect'] : null, function () {
    var options = {  // You'll need to tweak these settings per your app
        script: './server/index.js',
        nodeArgs: [],
        watch: ['./lib', './server', '!./server/public', '!./server/logs', 'gulpfile.js']
    };
    if (args.debug) {
        options.nodeArgs.push('--debug');
    }
    nodemon(options);
});

At the command line, you can run gulp start --debug to start nodemon in debug mode and launch node-inspector.

cudasteve commented Nov 3, 2015

Wish I would have found this thread a while back. In case it helps anyone in the future, here's an alternative solution I came up with that uses the nodeArgs option if you need a little more control over node-inspector or want to have it available as its own task.

var args = require('yargs').argv;
var nodeInspector = request('gulp-node-inspector');

gulp.task('inspect', function () {
    gulp.src([]).pipe(nodeInspector({  // You'll need to tweak these settings per your setup
        debugPort: 5859,
        webHost: '0.0.0.0',
        webPort: '8085',
        preload: false
    }));
});

gulp.task('start', (args.debug) ? ['inspect'] : null, function () {
    var options = {  // You'll need to tweak these settings per your app
        script: './server/index.js',
        nodeArgs: [],
        watch: ['./lib', './server', '!./server/public', '!./server/logs', 'gulpfile.js']
    };
    if (args.debug) {
        options.nodeArgs.push('--debug');
    }
    nodemon(options);
});

At the command line, you can run gulp start --debug to start nodemon in debug mode and launch node-inspector.

@360disrupt

This comment has been minimized.

Show comment
Hide comment
@360disrupt

360disrupt Nov 13, 2015

@cudasteve
You need to use yargs in gulp otherwise there will be nor arguments visible:
https://github.com/bcoe/yargs

Also I named optionsto nodeOptions to get it working.

360disrupt commented Nov 13, 2015

@cudasteve
You need to use yargs in gulp otherwise there will be nor arguments visible:
https://github.com/bcoe/yargs

Also I named optionsto nodeOptions to get it working.

@cudasteve

This comment has been minimized.

Show comment
Hide comment
@cudasteve

cudasteve Nov 13, 2015

@360disrupt thanks for the catches!

cudasteve commented Nov 13, 2015

@360disrupt thanks for the catches!

@jpierson

This comment has been minimized.

Show comment
Hide comment
@jpierson

jpierson Dec 29, 2015

I followed link from #92 which let me here bug neither execMap or exec seem to make any difference to me as I am still not able to get breakpoints to hit in VSCode.

  nodemon({
    script: 'server.js',
    ext: 'js html',
    exec: 'node --debug',
    env: {
      'NODE_ENV': 'development'
  })

jpierson commented Dec 29, 2015

I followed link from #92 which let me here bug neither execMap or exec seem to make any difference to me as I am still not able to get breakpoints to hit in VSCode.

  nodemon({
    script: 'server.js',
    ext: 'js html',
    exec: 'node --debug',
    env: {
      'NODE_ENV': 'development'
  })
@niftylettuce

This comment has been minimized.

Show comment
Hide comment
@niftylettuce

niftylettuce Feb 17, 2016

So how do we get DEBUG=* logs to show up for nodemon({})? I tried debug: true option and env: { 'DEBUG': '*' } as well.

niftylettuce commented Feb 17, 2016

So how do we get DEBUG=* logs to show up for nodemon({})? I tried debug: true option and env: { 'DEBUG': '*' } as well.

@niftylettuce

This comment has been minimized.

Show comment
Hide comment
@niftylettuce

niftylettuce Feb 17, 2016

Nevermind, I had stdout: false 😆

niftylettuce commented Feb 17, 2016

Nevermind, I had stdout: false 😆

@love2dishtech

This comment has been minimized.

Show comment
Hide comment
@love2dishtech

love2dishtech Jan 30, 2018

When we are trying to run it using VSCode using a launch configuration, it starts the gulp task in the inspect mode, which binds it to a random port. However, when we have the --inspect in the gulp task, it binds it to a new different random port. This does not allow the VSCode to track the code. Any particular solution for this ?

love2dishtech commented Jan 30, 2018

When we are trying to run it using VSCode using a launch configuration, it starts the gulp task in the inspect mode, which binds it to a random port. However, when we have the --inspect in the gulp task, it binds it to a new different random port. This does not allow the VSCode to track the code. Any particular solution for this ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment