inspect-brk
🔎A small helper to make debugging Node more convenient.
As you may know Node has great debugging capabilities if you use it together with a powerful inspector client. You have several options how to do that exactly, but I prefer to just use the --inspect-brk
flag when I run my script Node. It is passed directly to the Node binary.
Sometimes the call to the Node binary can be a little obfuscated however. This is probably most common if you use some command line tool. Look at this small project:
{
"name": "cool-example",
"version": "0.1.0",
"scripts": {
"build": "webpack --config webpack.build.js"
},
"devDependencies": {
"webpack": "^3.10.0"
}
}
How do you debug your build
step which uses webpack
? The webpack docs recommend to use --inspect-brk
which is what I'd recommend as well. But how do you inster --inspect-brk
here? You basically need write down the path to the webpack
binary like this:
{
"name": "cool-example",
"version": "0.1.0",
"scripts": {
"build": "webpack --config webpack.build.js",
"debug:build": "node --inspect-brk node_modules/.bin/webpack --config webpack.build.js"
},
"devDependencies": {
"webpack": "^3.10.0"
}
}
This works, but IMHO this way has two problems:
--config webpack.build.js
, but it could be a lot more.Of course you could rewrite the path just when you need it, but this can be cumbersome as well, if you need to do it a lot.
That's why I created inspect-brk
. It turns your example from above into this:
{
"name": "cool-example",
"version": "0.1.0",
"scripts": {
"build": "webpack --config webpack.build.js",
"debug:build": "inspect-brk build webpack"
},
"devDependencies": {
"inspect-brk": "^0.1.0",
"webpack": "^3.10.0"
}
}
You call inspect-brk
and pass the name of the script you want to debug (in this case build
) and than you pass one or more binary names which you want to inspect (in this case just webpack
).
Nothing big, but maybe helpful for some people 💕