How to enable debugging from a different host


#1

hi friends,
I am developing an Adonis app in a VM and I’d like to debug it with chrome inspect in my host OS.

How can I change the default IP address for debugging from 127.0.0.1 to 0.0.0.0?

Thanks for helping
Davide


#2

You need to tell node to run the debugger on 0.0.0.0.

node --inspect-brk=0.0.0.0:6000 app.js 

You also need to make sure that your VM opens the necessary ports so that external traffic can connect.

Then use Chrome (or VS Code) to attach to the debugger process.


#3

Thank you!
it works, I just had to change app.js to server.js, like this:

node --inspect-brk=0.0.0.0:6000 server.js

and of course make sure port 6000 is open with

sudo ufw allow 6000

This makes it, but an even better option would be to use the command provided by adonis, like

adonis serve --dev --debug

setting the debugger IP to 0.0.0.0 (or whatever) instead of 127.0.0.1. May be there is an option for this, but I have not been able to find it. I am just beginning my journey with Adonis (and loving it so far), where can I find the script referenced by “adonis serve”?

thanks
Davide


#4

You might be able to use NODE_OPTIONS env for that. I didn’t test it though.

https://nodejs.org/api/cli.html#cli_node_options_options


#5

Would be great, but for some reason I cannot get it to work :anguished: Looks like the problem is not with Adonis. Here test.js is a simple js file that prints an “Hello world” to the console.

node --inspect-brk test.js 
Debugger listening on ws://127.0.0.1:9229/f1956b6b-f74a-4ce3-b6d8-36513147ab89
For help see https://nodejs.org/en/docs/inspector

Using NODE_OPTIONS instead gives

NODE_OPTIONS="--inspect-brk" && node test.js 
Hello World

I guess I am doing something wrong but can’t figure out what. It looks like node is not honoring the env variable… version is 8.11.1 btw, and OS is ubuntu 16.04.

a bit puzzled.


#6

EDIT: never mind, I was wrong!


#7

Interestingly, I can’t get it to work on a Mac also. Node version v9.8.0.