Search code examples
node.jskibanakibana-4node-inspector

Debugging Kibana backend Node.js code


How to debug Kibana backend source code?

I presume, node-inspector could be used. And some extra configuration needed for package.json file to run debugger at npm start. But, I can't figure out the correct configuration syntax.


Solution

  • NODE_OPTIONS=--debug bin/kibana --dev
    

    If you want to break before starting:

    NODE_OPTIONS="--debug --debug-brk" bin/kibana --dev
    

    Alternatively, you can set the same variable when calling npm start:

    NODE_OPTIONS=--debug npm start
    

    You will see:

    Debugger listening on port 5858
    

    You can then use the node inspector by running node-inspector and opening http://127.0.0.1:8080/debug?port=5858.

    If you are debugging a remote server, you can either run node-inspector on the server and forward port 8080 through SSH, or you can run node-inspector locally and forward port 5858 through SSH.

    EDIT: As it was now mentioned in the comments, it might be necessary to edit the source and add debugger; at the beginning, otherwise breakpoints might not work correctly even when using --debug-brk. Not sure why, though.