Debugging NodeJS with Chrome Inspector / VSCode
MD
R
MarkdownNodeJS V8.* has advanced debugging built in. This recipe allows you to debug Node.js with Chrome DevTools (out of the box, without any plugins). Support for Node.js debuggability landed in Node.js master in May 2016. You can see it in action in the DevTools 2016 Google I/O talk.
Debugging Node V8
Chrome Inspector
node --inspect-brk index.js
This will open chrome dev tools. If you may want to install this plugin: https://chrome.google.com/webstore/detail/gnhhdgbaldcilmgcpfddgdbkhjohddkj
If id doesn't open, open chrome and set this URL
chrome://inspect
VSCode
Use the following .vscode/launch.json. Keep your entry *.js file open so that IntelliSense can pick it.
LAUNCH TEMPLATES
Launch in debug
// Use IntelliSense to learn about possible Node.js debug attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"program": "${file}"
}
]
}
Attach a debugger
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "attach",
"name": "Node: Nodemon",
"processId": "${command:PickProcess}",
"restart": true,
"protocol": "inspector",
},
]
}
Created on 8/30/2017