1

I am not able to attach debugger to the already running NodeJS web app.

Following are my VSCode launching configurations:

 "configurations": [
    {
        "type": "node",
        "request": "attach",
        "name": "Attach",        
        "port": 3001
    },

I am getting following error message:

Cannot connect to runtime process (reason: This socket has been ended by the other party).

Now, when I add protocol : inspector in the above configuration, it shows me the following error message:

Ensure Node was launched with --inspect. Cannot connect to runtime process, timeout after 10000 ms

I am currently using v8.6.0 version of NodeJS

Following are my configuration in package.json >> scripts:

 "scripts": {
    "start": "npm run build && npm run watch --inspect",
    "build": "npm run build-sass && npm run build-ts && npm run tslint && npm run copy-static-assets",
    "serve": "nodemon dist/server.js",
    "watch": "concurrently -k -p \"[{name}]\" -n \"Sass,TypeScript,Node\" -c \"yellow.bold,cyan.bold,green.bold\" \"npm run watch-sass\" \"npm run watch-ts\" \"npm run serve\"",
    "test": "jest --forceExit",
    "build-ts": "tsc",
    "watch-ts": "tsc -w",
    "build-sass": "node-sass src/public/css/main.scss dist/public/css/main.css",
    "watch-sass": "node-sass -w src/public/css/main.scss dist/public/css/main.css",
    "tslint": "tslint -c tslint.json -p tsconfig.json",
    "copy-static-assets": "node copyStaticAssets.js",
    "debug": "npm run build && npm run watch-debug",
    "serve-debug": "nodemon --inspect dist/server.js",
    "watch-debug": "concurrently -k -p \"[{name}]\" -n \"Sass,TypeScript,Node\" -c \"yellow.bold,cyan.bold,green.bold\" \"npm run watch-sass\" \"npm run watch-ts\" \"npm run serve-debug\""
  },

Folder Structure: enter image description here

13
  • How are you running the node server?
    – ifconfig
    Oct 11, 2017 at 5:39
  • simply by using "npm start" command in VS Terminal Oct 11, 2017 at 5:51
  • Ensure Node was launched with --inspect I think you need to run that with the --inspect flag.
    – ifconfig
    Oct 11, 2017 at 5:52
  • Could you please share the complete command. Also when try to run the Attach configuration, it giver following error message multiple time: [Node] GET /json 404 2.859 ms - 143 Oct 11, 2017 at 5:55
  • npm start --inspect? Alternatively, node bin/www --inspect
    – ifconfig
    Oct 11, 2017 at 5:56

1 Answer 1

2

Made it!

You will have to pass it to the serve before specifying the script. In addition, you will need to explicitly specify the port and the URL on the script:

"serve": "nodemon dist/server.js",

Change it to:

"serve": "nodemon --inspect=0.0.0.0:9229 dist/server.js",

Apparently vscode works when the URL is 0.0.0.0 and not 127.0.0.1.

Then, in launch.json:

"configurations": [
    {
      "type": "node",
      "request": "attach",
      "name": "Docker: Attach to Node",
      "port": 9229,
      "restart": true,
      "localRoot": "${workspaceFolder}/src",
      "remoteRoot": "./dist}
]

Pay attention to both localRoot and remoteRootwhich I've placed based on the picture you've shown me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.