The following shows you how to start node with the debug flag and use an SSH tunnel to access the right port.
Things you need:
- ssh access to the server
- ability to restart node app with
--debug
flag.
-
Stop the app
-
Restart with
--debug
forever -w -c 'node --debug' server.js
-
When it starts you should see something like
debugger listening on 5858
-
Setup webstorm
Run > Debug... > Edit Configurations... > Add new configuration > Node.js Remote Debug
- Host :
127.0.0.1
- Port :5858
-
Open SSH Tunnel to gain access to servers port 5858.
# open an ssh tunnel, send it to the bg, and wait 10 seconds for connections # once all connections are closed after 10 seconds then close the tunnel ssh -i sshkeyfilename -f -o ExitOnForwardFailure=yes -L 5858:127.0.0.1:5858 ec2-user@162.142.22.92 sleep 10
Replace sshkeyfilename with you ssh key file you use to connect to your remote server. Also, replace ec2-user@162.142.22.92 with your server.
-
Make sure you checkout the same code on your local machine as on the remote server.
-
Run the debugger in Webstorm (drop down in upper right next to the Bug icon - or the bug icon once you've run it once)
Once you are done with debugging, do not forget to restart the without --debug
flag