2

There appears to be a similar question as it about the predecessor to inspect, and I want to use inspect.

I have created a basic docker-compose stack from which I run my nodejs application. I want to listen for the debugger session and debug my JavaScript code within my local WebStorm.

I enter the container via

docker exec -it my_container bash

And I call my nodejs script with the debugger running via inspect:

node --inspect ./cli.js start mytask
Debugger listening on ws://127.0.0.1:9229/81006264-163c-40d7-bd75-64c5e4fca618
For help see https://nodejs.org/en/docs/inspector

The linked help is not helpful to me as it assumes that I want to use the inspect for a local run:

JetBrains WebStorm 2017.1+ and other JetBrains IDEs Create a new Node.js debug configuration and hit Debug. --inspect will be used by default for Node.js 7+. To disable uncheck js.debugger.node.use.inspect in the IDE Registry.

I want to attach to the run inside the docker container from my host WebStorm.

So when I run the script, it just completes never hitting any breakpoint.

I suppose I have to listen to the debugger, yet I do not know how.

I want my local WebStorm to connect to the nodejs debugger. I want to be able to debug within WebStorm as if I have run the nodejs script through WebStorm itself.

I tried digging through the docs yet I am unsure how to follow the guidelines.

I have exposed the default debug port 9229 to my local machine in my docker-compose.yml:

version: "3"
services:
    my_container:
        build: .
        command: "bash"
        hostname: my_container
        tty: true
        environment:
            TERM: xterm
        ports:
            - "9229:9229"

I have no idea on how to listen to the nodejs debugger in WebStorm.

k0pernikus
  • 60,309
  • 67
  • 216
  • 347

2 Answers2

6

You have to start your app with node --inspect-brk=0.0.0.0:9229 (0.0.0.0 is required as Node.js only binds to localhost by default) and then use Attach to Node.js/Chrome Run configuration to attach the debugger. Port should be set to 9229

lena
  • 90,154
  • 11
  • 145
  • 150
2

This is a workaround as I very much still want to use WebStorm's debugger, which is why this is not a solution for me but at least provides a way to debug:

For chrome's dev tools, you can use:

node --inspect-brk=0.0.0.0:9229 ./cli.js start mytask

It will show at:

chrome://inspect/#devices

You can click inspect and debug through the script.

--inspect-brk will break on first line, and I have to use the ip 0.0.0.0 for the dev-tools to pick it up.

k0pernikus
  • 60,309
  • 67
  • 216
  • 347