Debug NodeJS in Chrome
On server running Kubernetes cluster
- 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;
- Forward container debugging port (
9229
) to Kubernetes node:
kubectl port-forward $POD_NAME --address=0.0.0.0 9229:9229
On local machine
- Create ssh session to remote machine that will forward connection to port
9221
:
ssh -L 9221:localhost:9229 user@host
- Open Chrome and visit:
chrome://inspect
Click on Configure and add:
localhost:9221
To Target discovery settings.
- Under Remote Target #LOCALHOST you should see app.js.
- Go to Sources tab, Node and there will be the tree of the project.
- Set debugger.