Start Node.js in debug mode with inspector enabled
📦 Node.js-> Command Line
✨ The Prompt Phrase
node --inspect app.js
💻 Code Preview
📦 All-in-One Code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>node --inspect app.js - Start Node.js in debug mode with inspector enabled - Interactive Tutorial</title>
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;600;700&family=Fira+Code:wght@400;500&display=swap" rel="stylesheet">
<style>
:root {
--bg-primary: #0a0e27;
--bg-secondary: #151932;
--bg-card: #1e2139;
--accent-purple: #a855f7;
--accent-blue: #3b82f6;
--accent-green: #10b981;
--accent-red: #ef4444;
--accent-yellow: #f59e0b;
--text-primary: #f8fafc;
--text-secondary: #94a3b8;
--gradient-1: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
--gradient-2: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
--gradient-3: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
--shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Poppins', sans-serif;
background: var(--bg-primary);
color: var(--text-primary);
line-height: 1.6;
overflow-x: hidden;
}
.container {
max-width: 1200px;
margin: 0 auto;
padding: 20px;
}
/* Hero Section */
.hero {
text-align: center;
padding: 100px 20px;
background: var(--gradient-1);
position: relative;
overflow: hidden;
}
.hero::before {
content: '';
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: url('data:image/svg+xml,<svg width="100" height="100" xmlns="http://www.w3.org/2000/svg"><circle cx="50" cy="50" r="2" fill="white" opacity="0.1"/></svg>');
animation: float 20s linear infinite;
}
@keyframes float {
from { transform: translateY(0); }
to { transform: translateY(-100px); }
}
.hero-content {
position: relative;
z-index: 1;
}
.command-display {
display: inline-block;
background: rgba(0, 0, 0, 0.3);
padding: 20px 40px;
border-radius: 15px;
font-family: 'Fira Code', monospace;
font-size: 2rem;
margin: 30px 0;
border: 2px solid rgba(255, 255, 255, 0.2);
animation: pulse 2s ease-in-out infinite;
}
@keyframes pulse {
0%, 100% { transform: scale(1); }
50% { transform: scale(1.05); }
}
.hero h1 {
font-size: 3rem;
font-weight: 700;
margin-bottom: 20px;
animation: slideDown 0.8s ease-out;
}
.hero p {
font-size: 1.3rem;
opacity: 0.95;
animation: slideUp 0.8s ease-out;
}
@keyframes slideDown {
from { transform: translateY(-50px); opacity: 0; }
to { transform: translateY(0); opacity: 1; }
}
@keyframes slideUp {
from { transform: translateY(50px); opacity: 0; }
to { transform: translateY(0); opacity: 1; }
}
/* Progress Bar */
.progress-container {
position: sticky;
top: 0;
width: 100%;
height: 5px;
background: var(--bg-secondary);
z-index: 1000;
}
.progress-bar {
height: 100%;
background: var(--gradient-3);
width: 0%;
transition: width 0.3s ease;
}
/* Section Styles */
.section {
margin: 60px 0;
animation: fadeIn 0.8s ease-out;
animation-fill-mode: both;
}
@keyframes fadeIn {
from { opacity: 0; transform: translateY(30px); }
to { opacity: 1; transform: translateY(0); }
}
.section-title {
font-size: 2.5rem;
margin-bottom: 30px;
background: var(--gradient-3);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
background-clip: text;
display: inline-block;
}
.card {
background: var(--bg-card);
border-radius: 20px;
padding: 40px;
margin: 30px 0;
box-shadow: var(--shadow);
border: 1px solid rgba(255, 255, 255, 0.05);
transition: transform 0.3s ease, box-shadow 0.3s ease;
}
.card:hover {
transform: translateY(-5px);
box-shadow: 0 25px 70px rgba(0, 0, 0, 0.4);
}
/* Code Block */
.code-block {
background: #1e1e1e;
border-radius: 15px;
padding: 25px;
margin: 20px 0;
position: relative;
overflow: hidden;
font-family: 'Fira Code', monospace;
}
.code-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 15px;
padding-bottom: 15px;
border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}
.code-lang {
color: var(--accent-green);
font-weight: 600;
}
.copy-btn {
background: var(--accent-purple);
color: white;
border: none;
padding: 8px 16px;
border-radius: 8px;
cursor: pointer;
font-size: 0.9rem;
transition: all 0.3s ease;
}
.copy-btn:hover {
background: var(--accent-blue);
transform: scale(1.05);
}
.copy-btn.copied {
background: var(--accent-green);
}
pre {
margin: 0;
overflow-x: auto;
}
code {
color: #e0e0e0;
font-size: 0.95rem;
line-height: 1.6;
}
.code-comment {
color: #6a9955;
}
.code-keyword {
color: #569cd6;
}
.code-string {
color: #ce9178;
}
/* Steps */
.steps {
counter-reset: step-counter;
}
.step {
background: var(--bg-secondary);
border-radius: 15px;
padding: 30px;
margin: 20px 0;
position: relative;
padding-left: 80px;
transition: all 0.3s ease;
}
.step:hover {
background: var(--bg-card);
transform: translateX(10px);
}
.step::before {
counter-increment: step-counter;
content: counter(step-counter);
position: absolute;
left: 20px;
top: 50%;
transform: translateY(-50%);
width: 50px;
height: 50px;
background: var(--gradient-1);
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
font-size: 1.5rem;
font-weight: 700;
}
.step h3 {
color: var(--accent-blue);
margin-bottom: 10px;
}
/* Interactive Demo */
.demo-container {
background: var(--bg-secondary);
border-radius: 20px;
padding: 40px;
margin: 30px 0;
}
.terminal {
background: #1e1e1e;
border-radius: 15px;
padding: 20px;
font-family: 'Fira Code', monospace;
margin: 20px 0;
min-height: 200px;
}
.terminal-header {
display: flex;
gap: 8px;
margin-bottom: 15px;
}
.terminal-dot {
width: 12px;
height: 12px;
border-radius: 50%;
}
.terminal-dot.red { background: #ff5f56; }
.terminal-dot.yellow { background: #ffbd2e; }
.terminal-dot.green { background: #27c93f; }
.terminal-content {
color: #e0e0e0;
line-height: 1.8;
}
.terminal-prompt {
color: var(--accent-green);
}
.terminal-command {
color: var(--accent-blue);
}
.demo-button {
background: var(--gradient-1);
color: white;
border: none;
padding: 15px 40px;
border-radius: 50px;
font-size: 1.1rem;
font-weight: 600;
cursor: pointer;
transition: all 0.3s ease;
display: inline-flex;
align-items: center;
gap: 10px;
margin: 10px;
}
.demo-button:hover {
transform: scale(1.05);
box-shadow: 0 10px 30px rgba(168, 85, 247, 0.4);
}
/* Tabs */
.tabs {
display: flex;
gap: 10px;
margin-bottom: 20px;
flex-wrap: wrap;
}
.tab {
padding: 12px 24px;
background: var(--bg-secondary);
border: none;
border-radius: 10px;
color: var(--text-primary);
cursor: pointer;
transition: all 0.3s ease;
font-size: 1rem;
}
.tab:hover {
background: var(--bg-card);
}
.tab.active {
background: var(--gradient-1);
}
.tab-content {
display: none;
}
.tab-content.active {
display: block;
animation: fadeIn 0.5s ease-out;
}
/* Accordion */
.accordion-header {
cursor: pointer;
display: flex;
justify-content: space-between;
align-items: center;
padding: 20px;
background: var(--bg-secondary);
border-radius: 12px;
margin: 15px 0;
transition: all 0.3s ease;
}
.accordion-header:hover {
background: var(--bg-card);
}
.accordion-icon {
transition: transform 0.3s ease;
font-size: 1.2rem;
}
.accordion-icon.active {
transform: rotate(180deg);
}
.accordion-content {
max-height: 0;
overflow: hidden;
transition: max-height 0.3s ease;
}
.accordion-content.active {
max-height: 2000px;
}
.accordion-body {
padding: 20px;
background: var(--bg-secondary);
border-radius: 12px;
margin-top: 5px;
}
/* Tips */
.tip {
background: rgba(59, 130, 246, 0.1);
border-left: 4px solid var(--accent-blue);
padding: 20px;
border-radius: 10px;
margin: 20px 0;
}
.tip::before {
content: '💡 ';
font-size: 1.5rem;
}
.warning {
background: rgba(239, 68, 68, 0.1);
border-left: 4px solid #ef4444;
padding: 20px;
border-radius: 10px;
margin: 20px 0;
}
.warning::before {
content: '⚠️ ';
font-size: 1.5rem;
}
.success {
background: rgba(16, 185, 129, 0.1);
border-left: 4px solid var(--accent-green);
padding: 20px;
border-radius: 10px;
margin: 20px 0;
}
.success::before {
content: '✅ ';
font-size: 1.5rem;
}
/* Quiz */
.quiz-container {
background: var(--bg-card);
border-radius: 20px;
padding: 40px;
margin: 30px 0;
}
.quiz-question {
margin: 30px 0;
}
.quiz-question h3 {
color: var(--accent-purple);
margin-bottom: 20px;
}
.quiz-options {
display: flex;
flex-direction: column;
gap: 15px;
}
.quiz-option {
background: var(--bg-secondary);
padding: 20px;
border-radius: 12px;
cursor: pointer;
transition: all 0.3s ease;
border: 2px solid transparent;
}
.quiz-option:hover {
border-color: var(--accent-blue);
transform: translateX(10px);
}
.quiz-option.correct {
border-color: var(--accent-green);
background: rgba(16, 185, 129, 0.1);
}
.quiz-option.incorrect {
border-color: #ef4444;
background: rgba(239, 68, 68, 0.1);
}
.quiz-feedback {
margin-top: 15px;
padding: 15px;
border-radius: 10px;
display: none;
}
.quiz-feedback.show {
display: block;
animation: slideIn 0.5s ease-out;
}
@keyframes slideIn {
from { opacity: 0; transform: translateX(-20px); }
to { opacity: 1; transform: translateX(0); }
}
.quiz-feedback.correct {
background: rgba(16, 185, 129, 0.1);
border-left: 4px solid var(--accent-green);
}
.quiz-feedback.incorrect {
background: rgba(239, 68, 68, 0.1);
border-left: 4px solid #ef4444;
}
/* Cheat Sheet */
.cheat-sheet {
background: var(--gradient-1);
border-radius: 20px;
padding: 40px;
margin: 30px 0;
}
.cheat-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
gap: 20px;
margin-top: 30px;
}
.cheat-item {
background: rgba(255, 255, 255, 0.1);
backdrop-filter: blur(10px);
padding: 20px;
border-radius: 15px;
border: 1px solid rgba(255, 255, 255, 0.2);
}
.cheat-item h4 {
color: var(--accent-green);
margin-bottom: 10px;
}
.badge {
display: inline-block;
padding: 5px 15px;
background: var(--gradient-2);
border-radius: 20px;
font-size: 0.85rem;
font-weight: 600;
margin: 5px;
}
.highlight {
color: var(--accent-green);
font-weight: 600;
}
.comparison-table {
width: 100%;
border-collapse: collapse;
margin: 20px 0;
}
.comparison-table th,
.comparison-table td {
padding: 15px;
text-align: left;
border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}
.comparison-table th {
background: var(--bg-secondary);
color: var(--accent-blue);
font-weight: 600;
}
.comparison-table tr:hover {
background: rgba(255, 255, 255, 0.05);
}
/* Footer */
.footer {
text-align: center;
padding: 40px 20px;
background: var(--bg-secondary);
margin-top: 80px;
}
.footer p {
color: var(--text-secondary);
margin: 10px 0;
}
/* Confetti */
.confetti {
position: fixed;
width: 10px;
height: 10px;
z-index: 9999;
}
@keyframes confetti-fall {
to {
transform: translateY(100vh) rotate(360deg);
opacity: 0;
}
}
/* Responsive */
@media (max-width: 768px) {
.hero h1 {
font-size: 2rem;
}
.command-display {
font-size: 1.2rem;
padding: 15px 25px;
}
.hero p {
font-size: 1rem;
}
.section-title {
font-size: 1.8rem;
}
.card {
padding: 25px;
}
.step {
padding-left: 70px;
}
.step::before {
width: 40px;
height: 40px;
font-size: 1.2rem;
}
}
.browser-window {
background: var(--bg-card);
border-radius: 12px;
overflow: hidden;
margin: 20px 0;
border: 1px solid rgba(255, 255, 255, 0.1);
}
.browser-header {
background: var(--bg-secondary);
padding: 12px;
display: flex;
align-items: center;
gap: 8px;
}
.browser-dot {
width: 12px;
height: 12px;
border-radius: 50%;
}
.browser-content {
padding: 20px;
}
</style>
</head>
<body>
<div class="progress-container">
<div class="progress-bar" id="progressBar"></div>
</div>
<div class="hero">
<div class="hero-content">
<h1>🔍 Master Node.js Debugging</h1>
<div class="command-display">node --inspect app.js</div>
<p>Debug your Node.js apps like a pro with Chrome DevTools! 🛠️</p>
</div>
</div>
<div class="container">
<!-- What Is It Section -->
<section class="section" id="what-is-it">
<h2 class="section-title">🤔 What Is It?</h2>
<div class="card">
<p style="font-size: 1.2rem; margin-bottom: 20px;">
<strong>node --inspect app.js</strong> is like having <span class="highlight">X-ray vision</span> for your code! 👁️✨
</p>
<p style="margin-bottom: 20px;">
This command starts your Node.js application (<code>app.js</code>) with the <strong>debugger enabled</strong>. It opens a special port that allows debugging tools (like Chrome DevTools) to connect and inspect your running code in real-time!
</p>
<div class="tip">
<strong>Think of it like this:</strong> Regular <code>node app.js</code> is like driving with your eyes closed. <code>node --inspect app.js</code> is like having a dashboard with speedometer, GPS, and all the gauges! 🚗📊
</div>
<p style="margin-top: 20px;">
With the inspector, you can set breakpoints, step through code line-by-line, inspect variables, and see exactly what's happening inside your application while it runs!
</p>
</div>
</section>
<!-- Why Use It Section -->
<section class="section" id="why-use-it">
<h2 class="section-title">✨ Why Use It?</h2>
<div class="card">
<div class="cheat-grid">
<div class="cheat-item">
<h4>🐛 Find Bugs Fast</h4>
<p>See exactly where and why your code breaks. No more guessing!</p>
</div>
<div class="cheat-item">
<h4>🔬 Inspect Variables</h4>
<p>Check the values of variables at any point during execution.</p>
</div>
<div class="cheat-item">
<h4>⏸️ Pause Execution</h4>
<p>Set breakpoints to stop code at specific lines and investigate.</p>
</div>
<div class="cheat-item">
<h4>📊 Monitor Performance</h4>
<p>Profile your app to find slow functions and memory leaks.</p>
</div>
<div class="cheat-item">
<h4>🎯 Step Through Code</h4>
<p>Execute code line-by-line to understand the flow.</p>
</div>
<div class="cheat-item">
<h4>🌐 Use Chrome DevTools</h4>
<p>Leverage the powerful debugging tools you already know!</p>
</div>
</div>
</div>
</section>
<!-- How Does It Work Section -->
<section class="section" id="how-it-works">
<h2 class="section-title">⚙️ How Does It Work?</h2>
<div class="card">
<p style="margin-bottom: 30px;">Let's break down the magic! ✨</p>
<div class="code-block">
<div class="code-header">
<span class="code-lang">Command Anatomy</span>
<button class="copy-btn" onclick="copyCode(this, 'anatomy-cmd')">📋 Copy</button>
</div>
<pre><code id="anatomy-cmd">node --inspect app.js
│ │ │
│ │ └─ Your JavaScript file
│ └─ Flag to enable debugging
└─ Node.js runtime</code></pre>
</div>
<div class="steps">
<div class="step">
<h3>Start the Inspector</h3>
<p>Node.js opens a WebSocket server (usually on port 9229) that debugging clients can connect to.</p>
</div>
<div class="step">
<h3>Run Your App</h3>
<p>Your application starts running normally, but with debugging capabilities enabled.</p>
</div>
<div class="step">
<h3>Connect DevTools</h3>
<p>Open Chrome and navigate to <code>chrome://inspect</code> to see your Node.js process and connect to it!</p>
</div>
<div class="step">
<h3>Debug Away!</h3>
<p>Set breakpoints, inspect variables, and debug your code using the familiar Chrome DevTools interface! 🎉</p>
</div>
</div>
<div class="success" style="margin-top: 30px;">
<strong>Pro Tip:</strong> The inspector runs on port 9229 by default. You'll see a message like: <code>Debugger listening on ws://127.0.0.1:9229/...</code>
</div>
</div>
</section>
<!-- Live Demo Section -->
<section class="section" id="demo">
<h2 class="section-title">🎮 Interactive Demo</h2>
<div class="demo-container">
<h3 style="margin-bottom: 20px;">See the Inspector in Action!</h3>
<p style="margin-bottom: 30px;">Click the button to simulate starting Node.js with the inspector! 👇</p>
<button class="demo-button" onclick="startInspectorDemo()">
<span>▶️</span>
<span>Run node --inspect app.js</span>
</button>
<div class="terminal" id="demoTerminal" style="display: none;">
<div class="terminal-header">
<div class="terminal-dot red"></div>
<div class="terminal-dot yellow"></div>
<div class="terminal-dot green"></div>
</div>
<div class="terminal-content" id="terminalContent"></div>
</div>
<div id="devtoolsInfo" style="display: none; margin-top: 30px;">
<h4 style="color: var(--accent-green); margin-bottom: 15px;">🌐 How to Connect Chrome DevTools:</h4>
<div class="browser-window">
<div class="browser-header">
<div class="browser-dot" style="background: #ff5f56;"></div>
<div class="browser-dot" style="background: #ffbd2e;"></div>
<div class="browser-dot" style="background: #27c93f;"></div>
</div>
<div class="browser-content">
<p style="margin-bottom: 10px;"><strong>Step 1:</strong> Open Chrome browser</p>
<p style="margin-bottom: 10px;"><strong>Step 2:</strong> Navigate to <code style="background: var(--bg-primary); padding: 4px 8px; border-radius: 4px;">chrome://inspect</code></p>
<p style="margin-bottom: 10px;"><strong>Step 3:</strong> Click "inspect" under your Node.js target</p>
<p><strong>Step 4:</strong> Start debugging! 🎉</p>
</div>
</div>
</div>
</div>
</section>
<!-- Code Examples Section -->
<section class="section" id="code-examples">
<h2 class="section-title">💻 Command Variations</h2>
<div class="card">
<p style="margin-bottom: 30px;">Different ways to use the inspector! 🎨</p>
<div class="tabs">
<button class="tab active" onclick="switchTab('basic')">Basic</button>
<button class="tab" onclick="switchTab('custom-port')">Custom Port</button>
<button class="tab" onclick="switchTab('break')">Break on Start</button>
<button class="tab" onclick="switchTab('host')">Custom Host</button>
</div>
<div id="basic" class="tab-content active">
<div class="code-block">
<div class="code-header">
<span class="code-lang">Terminal</span>
<button class="copy-btn" onclick="copyCode(this, 'basic-code')">📋 Copy</button>
</div>
<pre><code id="basic-code">node --inspect app.js</code></pre>
</div>
<p style="margin-top: 15px;">
<strong>What it does:</strong> Starts your app with debugging enabled on default port 9229.
</p>
<p style="margin-top: 10px;">
<strong>When to use:</strong> Most common usage. App runs normally, you can attach debugger anytime.
</p>
</div>
<div id="custom-port" class="tab-content">
<div class="code-block">
<div class="code-header">
<span class="code-lang">Terminal</span>
<button class="copy-btn" onclick="copyCode(this, 'port-code')">📋 Copy</button>
</div>
<pre><code id="port-code">node --inspect=9230 app.js
# or
node --inspect=0.0.0.0:9230 app.js</code></pre>
</div>
<p style="margin-top: 15px;">
<strong>What it does:</strong> Uses a custom port instead of the default 9229.
</p>
<p style="margin-top: 10px;">
<strong>When to use:</strong> When port 9229 is already in use or you need a specific port.
</p>
</div>
<div id="break" class="tab-content">
<div class="code-block">
<div class="code-header">
<span class="code-lang">Terminal</span>
<button class="copy-btn" onclick="copyCode(this, 'break-code')">📋 Copy</button>
</div>
<pre><code id="break-code">node --inspect-brk app.js</code></pre>
</div>
<p style="margin-top: 15px;">
<strong>What it does:</strong> Starts with debugger AND pauses execution before your code runs!
</p>
<p style="margin-top: 10px;">
<strong>When to use:</strong> When you need to debug code that runs immediately on startup.
</p>
<div class="tip" style="margin-top: 15px;">
<strong>Super useful!</strong> This is perfect for debugging issues that happen during initialization!
</div>
</div>
<div id="host" class="tab-content">
<div class="code-block">
<div class="code-header">
<span class="code-lang">Terminal</span>
<button class="copy-btn" onclick="copyCode(this, 'host-code')">📋 Copy</button>
</div>
<pre><code id="host-code"># Listen on all interfaces (for remote debugging)
node --inspect=0.0.0.0:9229 app.js
# Localhost only (more secure)
node --inspect=127.0.0.1:9229 app.js</code></pre>
</div>
<p style="margin-top: 15px;">
<strong>What it does:</strong> Specifies which network interface to listen on.
</p>
<p style="margin-top: 10px;">
<strong>When to use:</strong> For remote debugging or when you need specific network configuration.
</p>
<div class="warning" style="margin-top: 15px;">
<strong>Security Warning:</strong> Using <code>0.0.0.0</code> exposes the debugger to your network. Only use on trusted networks!
</div>
</div>
</div>
</section>
<!-- Comparison Section -->
<section class="section" id="comparison">
<h2 class="section-title">⚔️ --inspect vs --inspect-brk</h2>
<div class="card">
<table class="comparison-table">
<thead>
<tr>
<th>Feature</th>
<th>--inspect</th>
<th>--inspect-brk</th>
</tr>
</thead>
<tbody>
<tr>
<td><strong>Starts Immediately</strong></td>
<td>✅ Yes</td>
<td>❌ No, waits for debugger</td>
</tr>
<tr>
<td><strong>Pauses on First Line</strong></td>
<td>❌ No</td>
<td>✅ Yes</td>
</tr>
<tr>
<td><strong>Best For</strong></td>
<td>Long-running apps, servers</td>
<td>Scripts, initialization bugs</td>
</tr>
<tr>
<td><strong>Can Attach Later</strong></td>
<td>✅ Yes</td>
<td>✅ Yes</td>
</tr>
<tr>
<td><strong>Debugging Port</strong></td>
<td>9229 (default)</td>
<td>9229 (default)</td>
</tr>
<tr>
<td><strong>Use Case</strong></td>
<td>Debug running application</td>
<td>Debug from the very start</td>
</tr>
</tbody>
</table>
<div class="tip" style="margin-top: 30px;">
<strong>Quick Decision Guide:</strong>
<ul style="margin-left: 20px; margin-top: 10px;">
<li>Use <code>--inspect</code> for servers and long-running processes</li>
<li>Use <code>--inspect-brk</code> for scripts and startup issues</li>
</ul>
</div>
</div>
</section>
<!-- Common Mistakes Section -->
<section class="section" id="mistakes">
<h2 class="section-title">❌ Common Mistakes</h2>
<div class="card">
<div class="accordion">
<div class="accordion-item">
<div class="accordion-header" onclick="toggleAccordion(this)">
<span><strong>1. Forgetting to Open Chrome DevTools</strong></span>
<span class="accordion-icon">▼</span>
</div>
<div class="accordion-content">
<div class="accordion-body">
<div class="warning">
<strong>The Problem:</strong> Running <code>node --inspect app.js</code> but not connecting a debugger!
</div>
<p style="margin-top: 15px;">The inspector is running, but you won't see any debugging interface unless you connect Chrome DevTools.</p>
<div class="success" style="margin-top: 15px;">
<strong>Solution:</strong>
<ol style="margin-left: 20px; margin-top: 10px;">
<li>Open Chrome browser</li>
<li>Go to <code>chrome://inspect</code></li>
<li>Click "inspect" under Remote Target</li>
</ol>
</div>
</div>
</div>
</div>
<div class="accordion-item">
<div class="accordion-header" onclick="toggleAccordion(this)">
<span><strong>2. Port Already in Use</strong></span>
<span class="accordion-icon">▼</span>
</div>
<div class="accordion-content">
<div class="accordion-body">
<div class="warning">
<strong>Error:</strong> <code>address already in use :::9229</code>
</div>
<p style="margin-top: 15px;">This happens when another Node.js process is already using the debugging port.</p>
<div class="success" style="margin-top: 15px;">
<strong>Solutions:</strong>
<ul style="margin-left: 20px; margin-top: 10px;">
<li>Kill the other process</li>
<li>Use a different port: <code>node --inspect=9230 app.js</code></li>
</ul>
</div>
</div>
</div>
</div>
<div class="accordion-item">
<div class="accordion-header" onclick="toggleAccordion(this)">
<span><strong>3. Using --inspect in Production</strong></span>
<span class="accordion-icon">▼</span>
</div>
<div class="accordion-content">
<div class="accordion-body">
<div class="warning">
<strong>Security Risk:</strong> Never run production apps with <code>--inspect</code> enabled!
</div>
<p style="margin-top: 15px;">The debugger gives full access to your application's memory and execution. This is a major security vulnerability!</p>
<div class="success" style="margin-top: 15px;">
<strong>Best Practice:</strong> Only use <code>--inspect</code> in development environments. For production debugging, use proper logging and monitoring tools.
</div>
</div>
</div>
</div>
<div class="accordion-item">
<div class="accordion-header" onclick="toggleAccordion(this)">
<span><strong>4. Not Setting Breakpoints</strong></span>
<span class="accordion-icon">▼</span>
</div>
<div class="accordion-content">
<div class="accordion-body">
<div class="warning">
<strong>Missing Out:</strong> Running the inspector but not using breakpoints!
</div>
<p style="margin-top: 15px;">Breakpoints are the most powerful debugging feature. They let you pause execution and inspect everything!</p>
<div class="tip" style="margin-top: 15px;">
<strong>How to Set Breakpoints:</strong>
<ul style="margin-left: 20px; margin-top: 10px;">
<li>In DevTools: Click the line number in the Sources tab</li>
<li>In Code: Add <code>debugger;</code> statement</li>
</ul>
</div>
</div>
</div>
</div>
<div class="accordion-item">
<div class="accordion-header" onclick="toggleAccordion(this)">
<span><strong>5. Confusing --inspect with --inspect-brk</strong></span>
<span class="accordion-icon">▼</span>
</div>
<div class="accordion-content">
<div class="accordion-body">
<div class="warning">
<strong>Common Confusion:</strong> Not knowing which flag to use!
</div>
<div class="code-block" style="margin-top: 15px;">
<pre><code><span class="code-comment"># App runs immediately</span>
node --inspect app.js
<span class="code-comment"># App waits for debugger to attach</span>
node --inspect-brk app.js</code></pre>
</div>
<p style="margin-top: 15px;"><strong>Remember:</strong> Use <code>--inspect-brk</code> when you need to debug code that runs right at startup!</p>
</div>
</div>
</div>
</div>
</div>
</section>
<!-- Pro Tips Section -->
<section class="section" id="pro-tips">
<h2 class="section-title">🚀 Pro Tips</h2>
<div class="card">
<div class="cheat-grid">
<div class="cheat-item">
<h4>🎯 Use debugger Statement</h4>
<p>Add <code>debugger;</code> in your code to create a breakpoint programmatically!</p>
</div>
<div class="cheat-item">
<h4>📝 VS Code Integration</h4>
<p>VS Code has built-in Node.js debugging! No need for Chrome DevTools.</p>
</div>
<div class="cheat-item">
<h4>🔄 Auto-Restart with Nodemon</h4>
<p><code>nodemon --inspect app.js</code> - Debug with auto-restart on file changes!</p>
</div>
<div class="cheat-item">
<h4>🌐 Remote Debugging</h4>
<p>Debug apps running in Docker or remote servers using port forwarding!</p>
</div>
<div class="cheat-item">
<h4>📊 CPU Profiling</h4>
<p>Use the Profiler tab in DevTools to find performance bottlenecks!</p>
</div>
<div class="cheat-item">
<h4>💾 Memory Snapshots</h4>
<p>Take heap snapshots to find memory leaks and analyze memory usage!</p>
</div>
</div>
<div class="tip" style="margin-top: 30px;">
<strong>🎓 Advanced Technique:</strong> Use <code>node --inspect --require ./debug-setup.js app.js</code> to load debugging utilities before your app starts!
</div>
<div class="success" style="margin-top: 20px;">
<strong>💡 Quick Workflow:</strong>
<ol style="margin-left: 20px; margin-top: 10px;">
<li>Start: <code>node --inspect-brk app.js</code></li>
<li>Open: <code>chrome://inspect</code></li>
<li>Click: "inspect" on your target</li>
<li>Debug: Set breakpoints and step through! 🎉</li>
</ol>
</div>
</div>
</section>
<!-- Quiz Section -->
<section class="section" id="quiz">
<h2 class="section-title">🎯 Knowledge Check Quiz</h2>
<div class="quiz-container">
<p style="margin-bottom: 30px;">Test your debugging knowledge! Click on the correct answer. 🧠</p>
<div class="quiz-question">
<h3>Question 1: What does node --inspect do?</h3>
<div class="quiz-options">
<div class="quiz-option" onclick="checkAnswer(this, false, 1)">
A
Live Preview