How to setup node-inspector with vagrant?

2019-05-31 07:57发布

问题:

I have an meanjs application running on a vagrant box. My vagrantfile is as follows

 config.vm.network "forwarded_port", guest: 27017, host: 27016 #mongodb
 config.vm.network "forwarded_port", guest: 1337, host: 1338 #node inspector

 config.vm.network "private_network", ip: "192.168.33.10"

node inspector configuration is as follows

'node-inspector': {
  custom: {
    options: {
      'web-port': 1337,
      'web-host': 'localhost',
      'debug-port': 5858,
      'save-live-edit': true,
      'no-preload': true,
      'stack-trace-limit': 50,
      'hidden': []
    }
  }
},

I am not able to get the node inspector working on my host machine whenever

http://192.168.33.10:1338/debug?port=5858

with vagrant I am able to get the node-inspector working on the local machine without vagrant

回答1:

When you use static IP you do not need to forward port. Forward port is mainly used when you use bridge adapter. If you go to http://192.168.33.10:1337/debug?port=5858 you should see your inspector



回答2:

I figured the problems was the number of concurrent tasks configured for grunt-concurrent module. By default its equal to the number of cores in the pc. In my case it was two. So My node-inspecter module configuration in gruntfile.js

 concurrent: {
  default: ['nodemon', 'watch'],
  debug: ['node-inspector', 'nodemon', 'watch'],
  options: {
    logConcurrentOutput: true,
    limit: 5
  }

There is also no debug in the hyperlink .It should be.

http://192.168.33.10:1337/?port=5858

Port forwarding was required for both the ports to get the node inspector

config.vm.network "forwarded_port", guest: 1337, host: 1337   
config.vm.network "forwarded_port", guest: 5858, host: 5858