Debugging Locally
Set breakpoints, step through code, and inspect variables in your route handlers and custom policies while your gateway runs locally.
VS Code
New projects created with create-zuplo-api ship with a .vscode/launch.json
that's ready to go.
-
Open Run and Debug (View > Run and Debug).
-
Select Launch & Attach Zuplo and click the green play button.
-
Set a breakpoint, then send a request to the route. See Breakpoints not binding? if it doesn't stop.
If your project doesn't have a .vscode/launch.json, create one with these
contents and repeat the steps above:
Code
WebStorm, IntelliJ, and other editors
-
Start the gateway with the debug port open:
Code -
Add an Attach to Node.js/Chrome run configuration pointed at
localhost:9229and run it in debug mode. In JetBrains IDEs, enable Reconnect automatically so it re-attaches after each reload. -
Set a breakpoint, then send a request to the route. See Breakpoints not binding? if it doesn't stop.
Don't use "Debug the npm run dev script." Your policies run in a separate
runtime process, so debugging the npm script attaches to the wrong process and
breakpoints never bind. Always start with --debug-port and attach to it, as
above.
Breakpoints not binding?
A breakpoint may show as unbound (a hollow marker) until the route runs for the first time — each policy is loaded on first use, so the debugger has nothing to attach to until then. To fix it:
- Send a request to the route once. The breakpoint marker turns solid.
- Send the request again — execution now stops at your breakpoint.
Limitations
You can only step through your own code. System code provided by Zuplo is minified and stripped of source maps, so you can't step into it.