Debugging CAP Node.js with VS Code

Configure the VS Code debugger for a CAP Node.js project, set breakpoints in service handlers, inspect the req object, and use the Debug Console.

Debugging CAP Node.js with VS Code

VS Code's Node.js debugger works natively with CAP — no extra plugins needed.

Method 1 — attach to cds watch (easiest)

Step 1 — start cds watch with inspect flag

node --inspect node_modules/.bin/cds watch
# or use the npm script approach:

Add to package.json:

{
  "scripts": {
    "start:debug": "node --inspect node_modules/.bin/cds watch"
  }
}

Then run:

npm run start:debug

You'll see: Debugger listening on ws://127.0.0.1:9229/...

Step 2 — attach VS Code

Press F5 → if prompted, select Node.js: Attach and accept the default port 9229.

Method 2 — launch.json (full control)

Create .vscode/launch.json:

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "CAP Node.js",
      "type": "node",
      "request": "launch",
      "program": "${workspaceFolder}/node_modules/.bin/cds",
      "args": ["watch"],
      "cwd": "${workspaceFolder}",
      "console": "integratedTerminal",
      "restart": true
    }
  ]
}

Press F5 to start. The integrated terminal shows cds watch output.

Set a breakpoint in a handler

Open srv/cat-service.js, click the line gutter to set a breakpoint:

this.before('READ', 'Products', req => {
  // ← breakpoint here
  console.log('Query:', req.query);
});

Trigger a GET request to /catalog/Products — VS Code will pause at the breakpoint.

Inspect the req object

When paused, hover over req in the editor or open the Debug Console (bottom panel) and type:

req.data           // body for CREATE/UPDATE
req.query          // parsed CQL query object
req.user.id        // logged-in user
req.headers        // HTTP headers

Inspect the database (SQLite in dev)

In the Debug Console:

// SELECT is on cds.ql — destructure it first
const { SELECT } = cds.ql
const db = cds.db
await db.run(SELECT.from('my.namespace.Products'))

Hot reload with breakpoints

cds watch restarts on file change. VS Code reconnects the debugger automatically (the restart: true in launch.json handles this).

Sign in for progress tracking & Q&A →