A debugger can easily be used to help pinpointing issues with the code. Follow these steps.
- First, make sure to run the
npm run build:watch
, this will generate source maps - Run the command you want via
node --inspect
, like so:node --inspect ./dist/bin/vip-dev-env-import-sql.js
- Note the port the debugger is listening on:
Debugger listening on ws://127.0.0.1:9229/db6c03e9-2585-4a08-a1c6-1fee0295c9ff
For help, see: https://nodejs.org/en/docs/inspector
- In your editor of choice attach to the debugger. For VSCode: Hit 'Run and Debug' panel, hit the "gear" icon (open launch.json), make your
Attach
configuration entry to look like so: Make sure theport
matches the port from step 3, and theruntimeExecutable
matches the exactnode
executable you ran. If you use a version manager likenvm
, its especially important to check this.
{
"name": "Attach",
"port": 9229,
"request": "attach",
"skipFiles": [ "<node_internals>/**" ],
"type": "node",
"runtimeExecutable": "/Users/user/.nvm/versions/node/v14.18.2/bin/node"
}
- Set your breakpoints, add debug code, and hit the play button.
- Confirm that you attached the debugger to continue command execution.
- Resolve the problem.
- [Optional but recommended] Pay it forward and implement a similar approach to other internal/external tooling.