- Start Node application (
yarn inspect
) - Open
http://localhost:1337
- Open Chrome Dev Tools
- Click on the green Node.js icon (Open dedicated DevTools for Node.js)
- Set a breakpoint on line 8
- App will have stopped at line 8
- Use the actions to step through the code
- Close Chrome tab
- Click on line 8 to set a red dot
- Open Debugging Panel (Cmd + Shift + D)
- index.js 8 now visible in the Breakpoints section
- Create configuration
- Debug > Add Configuration > Node > Launch Program
- Click on the Green triangle icon
- VS Code will start the app inside itself and open the Debug Console
curl localhost:1337
- App will have stopped at line 8
- Use the actions to step through the code
- Click the red "Disconnect" icon to disconnect
- Create Configuration
- Debug > Add Configuration > Node > Attach by Process
- Select the processId (which in our case is the one with
watchexec
) - Start server
yarn inspect
- Click the green triangle ("Start debugging")
- Debugger panel should show "App listening on port 1337"
curl localhost:1337
- App will have stopped at line 8
- Use the actions to step through the code
- Click the red "Disconnect" icon to disconnect
- Create configuration
- Debug > Add Configuration > Node > Attach
- note that the default port when using the --inspect flag
- Start server
yarn inspect
- Click the green triangle
curl localhost:1337
- Create a separate service "inspect" definition in the
docker-compose.yml
- put the commands on separate lines
- Start server
docker-compose up inspect
- Open Chrome Dev Tools
- Click resume
- Set a breakpoint
curl localhost:1337
- App will have stopped
As per the plain JS steps May need to set breakpoints first, before starting server (to avoid the invalid breakpoint error; valid breakpoints are red)
https://scotch.io/tutorials/debugging-node-code-in-vs-code https://blog.risingstack.com/how-to-debug-a-node-js-app-in-a-docker-container/