Skip to main content

Debug NodeJS in Chrome

On server running Kubernetes cluster

  1. Set up inspection in Node container:
kubectl edit deployment api-gateway
Containers:
api-gateway:
Command:
...
node --inspect-brk=0.0.0.0:9229 app.js;
  1. Forward container debugging port (9229) to Kubernetes node:
kubectl port-forward $POD_NAME --address=0.0.0.0 9229:9229

On local machine

  1. Create ssh session to remote machine that will forward connection to port 9221:
ssh -L 9221:localhost:9229 user@host
  1. Open Chrome and visit:
chrome://inspect

Click on Configure and add:

localhost:9221

To Target discovery settings.

  1. Under Remote Target #LOCALHOST you should see app.js.
  2. Go to Sources tab, Node and there will be the tree of the project.
  3. Set debugger.