Effectively debugging web apps takes effort, especially when an HTTP request goes through multiple layers before reaching your web app. Follow the steps below to debug a specific app. You can choose to debug in an environment deployed to Upsun or with your app running locally but connected to deployed services. In either case, make sure to debug in a preview environment. For more general information, see how to troubleshoot development.
1. Create a new environment
Start by creating a new environment completely isolated from production but with the same data for debugging:
2. Get access
Remote
Local
Access your app container via SSH:
To access deployed apps and services, open tunnels to everything your app has relationships with:
In the same terminal, set the relevant environment variables:
3. Run your app in inspect mode
Remote
Local
Stop the current process and restart it in inspect mode:
In the same terminal as the previous step, run the following command:
Replace <START_FILE> with the file defined for your app’s start command.
You get output something like this:
4. (If debugging remotely) Forward the debugger port locally
In another terminal, create an SSH tunnel that forwards to the 9229 port:
5. Connect the debugger
You can now connect the debugger as if you were debugging a local application. See examples with some common tools:
Using Chrome developer tools
Using Visual Studio Code
Go to chrome://inspect.
Find your running app under the Remote Target list.
Click inspect to start the debugger.
Use the Node.js: Attach debugger option.If you haven’t created the option:
- On the Run and Debug tab, click
create a launch.json file. - Select
Node.jsas the environment. - In the
configurationsarray, start IntelliSense (usually ctrl+space). - Select
Node.js: Attach. - Make sure the port is the same as in step 4 above.
Once you have the option:In the Run and Debug tab, select Attach from the menu and click Start Debugging (the green arrow).See more on Node.js debugging in Visual Studio Code.
Now when you load the site at your deployed URL (if debugging remote) or localhost (if debugging locally), the local debugger you’ve attached is called. Set breakpoints:
Remote
Local
In the JavaScript files from your remote site:
On the Run and Debug tab under Loaded Scripts find Attach: Remote Process > /app.
Directly in your source files.
Other issues
pm2 process manager blocks other processes
If you’re using the pm2 process manager to start your app from a script,
you might find it daemonizes itself and blocks other processes (such as backups) by constantly respawning.
This may happen even if you use the --no-daemon flag.
Instead of using a script, call pm2 start directly in your start command.