Chrome DevTools Debugging
Basic Inspector
Start your program with the--inspect flag:
Break on Start
Pause execution immediately on the first line:Custom Inspector Port
Specify a custom port for the inspector:VS Code Debugging
Launch Configuration
Create.vscode/launch.json:
.vscode/launch.json
Using the Debugger
Deno Extension for VS Code
Install the official Deno extension for enhanced debugging and development experience.Console Debugging
Basic Logging
Console Methods
Debugger Statement
Use thedebugger statement to programmatically break:
Debugging Tests
Test with Inspector
VS Code Test Debugging
Use the test configuration from launch.json:Remote Debugging
Debug applications running on remote servers:Server Side
Local Side
Set up SSH port forwarding:localhost:9229.
Environment Variables for Debugging
Performance Profiling
CPU Profiling
- Go to the Profiler tab
- Click “Start”
- Run your code
- Click “Stop”
- Analyze the flame graph
Memory Profiling
- Go to the Memory tab
- Take heap snapshots
- Compare snapshots to find memory leaks
Source Maps
Deno automatically generates source maps for TypeScript, so you can debug TypeScript code directly.Custom Source Maps
If using a bundler or transpiler:Debugging Common Issues
Permission Errors
Permission Errors
Run with
--allow-all during debugging:Module Not Found
Module Not Found
Check the import path and ensure the file exists:
Type Errors
Type Errors
Check types without running:
Network Issues
Network Issues
Enable verbose logging:
Best Practices
Use descriptive logs
Include context in log messages:
Remove debugger statements
Don’t commit
debugger statements to production codeUse source maps
Ensure source maps are enabled for accurate debugging
Log structured data
Use
console.table() for complex objects:Example: Debugging a Web Server
main.ts
- Open
chrome://inspect - Set breakpoints
- Make requests to
http://localhost:3000 - Step through the code