2

I have launch configuration for my Nodejs with ExpressJs application, the debugger mode starts and then immediately stops.. It doesn't keep on listening.. any help is much appreciated.

{
    "name": "Launch via NPM",
    "type": "node",
    "request": "launch",
    "cwd": "${workspaceFolder}/index.js",
    "runtimeExecutable": "npm",
    "runtimeArgs": [
        "run-script", "debug"
    ],
    "port": 9229
}

Below is my server configuration

app.listen(PORT, HOST, () => {
  process.stdout.write(Server is listening on ${PORT} (${NODE_ENV})\n)
  log.info(Server is listening on ${PORT} (${NODE_ENV})\n)
})

Start commands in package.json

"devStart": "nodemon --exec babel-node index.js",

"start": "per-env",

"start:development": "nodemon --exec babel-node index.js",

SpeedRacer
  • 21
  • 4
  • can u update your `start` command(if you have any in package.json) and folder structure.? – kgangadhar Feb 16 '18 at 15:27
  • I had a similar issue and was able to get around it by attaching the debugger by PID. At least that way I didn't need a configuration for debugging. – Mickers Feb 16 '18 at 15:32
  • @Mickers, where exactly have you attached the PID ? – SpeedRacer Feb 16 '18 at 15:41
  • See [this](https://stackoverflow.com/questions/31711286/vscode-debug-es6-application), It may be helpful. – kgangadhar Feb 16 '18 at 15:43
  • 2
    @SpeedRacer while your app is running open up the debug tab and on the top left to choose from the drop-down "Add Configuration" -> node.js. Then select Attach by Process ID. Once you hit the start button (green arrow next to the drop-down) it will ask you to choose which process ID to attach to. You should see the path to your application listed there. – Mickers Feb 16 '18 at 15:50
  • Ok.. now I am getting the following error though I have installed async npm module --- Debugger listening on ws://127.0.0.1:6161/65152437-efc2-4412-bf2b-f73e8791fc77 Debugger attached. module.js:538 throw err; ^ Error: Cannot find module 'async-file' – SpeedRacer Feb 16 '18 at 16:02

1 Answers1

0

The issue is resolved by below steps..

1.) Followed the steps as suggested by Mickers in the above comments

2.) (for the async module issue ) rm -rf node_modules

followed by -- npm install

The debugger is successfully attached

SpeedRacer
  • 21
  • 4