Local Development

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.

  1. Open Run and Debug (View > Run and Debug).

  2. Select Launch & Attach Zuplo and click the green play button.

  3. 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:

JSON.vscode/launch.json
{ "version": "0.2.0", "configurations": [ { "type": "node", "request": "launch", "name": "Launch Zuplo", "runtimeExecutable": "npx", "runtimeArgs": ["zuplo", "dev", "--debug-port", "9229", "--port", "9000"], "console": "integratedTerminal", "internalConsoleOptions": "neverOpen" }, { "name": "Zuplo Gateway", "type": "node", "request": "attach", "restart": true, "port": 9229 } ], "compounds": [ { "name": "Launch & Attach Zuplo", "configurations": ["Launch Zuplo", "Zuplo Gateway"] } ] }

WebStorm, IntelliJ, and other editors

  1. Start the gateway with the debug port open:

    TerminalCode
    npx zuplo dev --debug-port 9229
  2. Add an Attach to Node.js/Chrome run configuration pointed at localhost:9229 and run it in debug mode. In JetBrains IDEs, enable Reconnect automatically so it re-attaches after each reload.

  3. 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:

  1. Send a request to the route once. The breakpoint marker turns solid.
  2. 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.

Last modified on