Skip to content

Instantly share code, notes, and snippets.

@harry1064
Last active October 27, 2017 06:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save harry1064/b96fc2821befcda45b597e29194e9d43 to your computer and use it in GitHub Desktop.
Save harry1064/b96fc2821befcda45b597e29194e9d43 to your computer and use it in GitHub Desktop.
Remote Node.js Debug using webstorm

Debugging node running on a remote server

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.

Debugging using Webstorm

  1. Stop the app

  2. Restart with --debug

    forever -w -c 'node --debug' server.js
    
  3. When it starts you should see something like debugger listening on 5858

  4. Setup webstorm

    1. Run > Debug... > Edit Configurations... > Add new configuration > Node.js Remote Debug
    2. Host : 127.0.0.1 - Port : 5858
  5. 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.

  6. Make sure you checkout the same code on your local machine as on the remote server.

  7. 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)

Last Steps

Once you are done with debugging, do not forget to restart the without --debug flag

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment