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.
VS Code's Node.js debugger works natively with CAP — no extra plugins needed.
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/...
Press F5 → if prompted, select Node.js: Attach and accept the default port 9229.
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.
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.
req objectWhen 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
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'))
cds watch restarts on file change. VS Code reconnects the debugger automatically (the restart: true in launch.json handles this).