3

How can I call an API which is being served by the vscode debugger? I would usually call http://localhost:3000/api/plugins, but clearly my project isn't served on that port. My launch.json look like this:

   {
        "name": "Launch",
        "type": "node",
        "request": "launch",
        "program": "${workspaceRoot}/server/app.js",
        "stopOnEntry": false,
        "args": [],
        "cwd": "${workspaceRoot}",
        "preLaunchTask": null,
        "runtimeExecutable": null,
        "runtimeArgs": [
            "--nolazy"
        ],
        "env": {
            "NODE_ENV": "development"
        },
        "console": "internalConsole",
        "sourceMaps": false,
        "outDir": null
    },

and the output from the debug console:

node --debug-brk=12834 --nolazy server\app.js 
Debugger listening on [::]:12834
MongoDB Connection Succesful

I have tried the API with Postman on both localhost:12834 and localhost:5858 (which is the port in the attach configuration - neither work...

George Edwards
  • 8,979
  • 20
  • 78
  • 161

1 Answers1

2

In visual studio code, you can debug node.js code with its inbuilt debugger. For that you don't need to call api with the debugging port(In your case 12834). You just need to call with port defined in your express configuration (generally 3000).

You have to start debugging from visual studio code with F5. So, your debugging start for the project and you need to put break point on method, you want to debug. So, when your api call from frontend, you will get point on vscode.

Anavar Bharmal
  • 329
  • 2
  • 7
  • 19