Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to call API from backend under vscode debugger?

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

like image 584
George Edwards Avatar asked Mar 14 '26 01:03

George Edwards


1 Answers

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.

like image 170
Anavar Bharmal Avatar answered Mar 16 '26 16:03

Anavar Bharmal