How Do I debug NodeJS on Heroku?
Hi,
I am running NodeJS on Heroku free account and my laptop is connected to a router. I followed these docs to connect the IntelliJ IDE to Heroku and I am able to deploy the project, but I am not able to debug it.
https://www.jetbrains.com/help/idea/run-debug-configuration-heroku-deployment.html#d1929637e38
https://stackoverflow.com/questions/38568917/how-could-i-debug-a-node-js-app-deploy-on-heroku
When deploying the app for debug,
I get the following in the Herokou logs
app[web.1]: [heroku-exec] Starting
app[web.1]: Debugger listening on ws://127.0.0.1:9229/3bdee650-712c-4517-83ac-b70c50c81bf0
and the following error message in IntelliJ IDEA
Error running 'invulnerable-formage-12345':
Unable to open debugger port (127.0.0.1:9229): java.io.IOException "handshake failed - unrecognized message from target VM"
Thanks for your help.
---- The details below were fixed according to my understanding of the answer below --------------
I am using port 9229, so I
1. I set my router to forward all incoming traffic from ALL IPs port 9229 to my laptop's private IP port 9229
2. I set IntelliJ IDE configuration to work with my Heroku account. This part works and I am able to deploy my app.
3. In my configuration profile for debug I put :
Debug Host: 141.236.15.153
The IP I get from https://www.whatismyip.com/ - my public IP:
Debug port: 9229
4. I ran the following commands in DIFFERENT Windows 10 terminal windows. commands:
heroku ps:exec (I don't do a Ctrl+C to break out of the $ prompt)
heroku ps:forward 9229 (keep open while debugging)
5. My procfile has this singe line:
web: node --inspect-brk index.js
6. my launch.json file is:
{
"type": "node",
"request": "attach",
"name": "Heroku",
"address": "141.236.15.153",
"port": 9229,
"protocol": "inspector",
"localRoot": "${workspaceFolder}",
"remoteRoot": "/app"
}
Please sign in to leave a comment.
1. you have set up port forwarding for port 5858, but node --inspect listens on 9229 by default
2. I'm not sure what 31245 is (port your application is listening on?), but the port in Attach to Node.js/Chrome configuration should be a debugger port, not server port (9229 or whatever port you configure port forwarding for).
You can use the
launch.jsonfrom https://stackoverflow.com/questions/38568917/how-could-i-debug-a-node-js-app-deploy-on-heroku as example3. I'd suggest using --inspect-brk instead of --inspect to make sure that the app execution is suspecned until the debugger is attached, otherwise you will miss breakpoints in code executed when your application starts
Hi Elena,
Thanks for the quick reply.
I fixed the details in my question - As you indicated I mentioned incorrect ports in the details - and added more details on my setup and launch.json file.
I changed the address IP in launch.json to my public IP and forward all incoming traffic to my router on port 9229 to my laptop's private IP and port 9229.
I am still failing to get debug to work for me and would appreciate your help.
Best regards,
Shlomi.
>my launch.json file is
hmm... IDEA doesn't use launch.json - are you trying to debug with VSCode?
Also, I'd suggest changing host in your run configuration from "141.236.15.153" to "localhost"