I was previously using gulp and running gulp to start my application and listeners from the Visual Studio Code debugger but have recently needed to switch to running scripts
My situation was a little different. I was testing an api server and also a client (for that api server). this is what worked for me.
package.json (of the api server)
"scripts": {
"start": "DEBUG=users:* PORT=3333 SEQUELIZE_CONNECT=models/sequelize-sqlite.yaml node user-server",
"debug": "DEBUG=users:* PORT=3333 SEQUELIZE_CONNECT=models/sequelize-sqlite.yaml node --inspect-brk user-server"
},
launch.json (of the api server)
"configurations": [
{
"type": "node",
"request": "attach",
"name": "Attach to Remote",
"address": "localhost",
"port": 9229,
"localRoot": "${workspaceFolder}",
"remoteRoot": "${workspaceFolder}",
"skipFiles": [
"<node_internals>/**"
]
},
with that done, I would do the following.
That would run the api server, and also have the debugger start debugging for me.
Finally, to actually test the api client, I would run the api client file like this. note - all files are in the root folder. if your files are distributed elsewhere, you will have to modify the localRoot and remoteRoot accordingly.
PORT=3333 node users-add-testthisman1.js
Here, its important to note the client configuration I had.
var client = restify.createJsonClient({
url: 'http://localhost:'+process.env.PORT,
version: '*'
});
If you have a different configuration, then, your command line will have different arguments, of course.