Set the maximum old space size for V8 heap memory to 4GB
๐ฆ Node.js-> Command Line
โจ The Prompt Phrase
node --max-old-space-size=4096 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>Set the maximum old space size for V8 heap memory to 4GB - Interactive Tutorial</title>
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;600;700;900&family=Fira+Code:wght@400;500;600&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;
--accent-pink: #ec4899;
--accent-cyan: #06b6d4;
--accent-lime: #84cc16;
--accent-orange: #fb923c;
--text-primary: #f8fafc;
--text-secondary: #94a3b8;
--gradient-memory: linear-gradient(135deg, #ec4899 0%, #fb923c 100%);
--gradient-heap: linear-gradient(135deg, #3b82f6 0%, #06b6d4 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;
}
.progress-container {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 5px;
background: var(--bg-secondary);
z-index: 1000;
}
.progress-bar {
height: 100%;
background: var(--gradient-memory);
width: 0%;
transition: width 0.3s ease;
}
.hero {
text-align: center;
padding: 100px 20px;
background: var(--gradient-memory);
position: relative;
overflow: hidden;
border-radius: 0 0 50px 50px;
}
.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;
}
.memory-icon {
font-size: 5rem;
margin-bottom: 20px;
animation: memoryPulse 2s ease-in-out infinite;
}
@keyframes memoryPulse {
0%, 100% { transform: scale(1); }
50% { transform: scale(1.15); }
}
.command-display {
display: inline-block;
background: rgba(0, 0, 0, 0.4);
padding: 25px 40px;
border-radius: 15px;
font-family: 'Fira Code', monospace;
font-size: 1.1rem;
margin: 30px 0;
border: 3px solid rgba(255, 255, 255, 0.3);
animation: pulse 2s ease-in-out infinite;
color: white;
font-weight: 600;
}
@keyframes pulse {
0%, 100% { transform: scale(1); }
50% { transform: scale(1.05); }
}
.hero h1 {
font-size: 3.5rem;
font-weight: 900;
margin-bottom: 20px;
color: white;
text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
}
.hero p {
font-size: 1.4rem;
opacity: 0.95;
color: white;
}
.section {
margin: 60px 0;
}
.section-title {
font-size: 2.5rem;
margin-bottom: 30px;
background: var(--gradient-memory);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
background-clip: text;
display: inline-block;
font-weight: 700;
}
.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;
}
.card:hover {
transform: translateY(-5px);
}
.code-block {
background: #1e1e1e;
border-radius: 15px;
padding: 25px;
margin: 20px 0;
font-family: 'Fira Code', monospace;
position: relative;
}
.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);
}
.terminal-dots {
display: flex;
gap: 6px;
}
.terminal-dot {
width: 12px;
height: 12px;
border-radius: 50%;
}
.dot-red { background: #ff5f56; }
.dot-yellow { background: #ffbd2e; }
.dot-green { background: #27c93f; }
.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.8;
}
.code-comment { color: #6a9955; }
.code-string { color: #ce9178; }
.code-keyword { color: #569cd6; }
.code-property { color: #9cdcfe; }
.code-flag { color: #fb923c; font-weight: 600; }
.code-number { color: #b5cea8; }
.steps {
counter-reset: step-counter;
}
.step {
background: var(--bg-secondary);
border-radius: 15px;
padding: 30px;
margin: 20px 0;
position: relative;
padding-left: 100px;
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: 60px;
height: 60px;
background: var(--gradient-memory);
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
font-size: 1.8rem;
font-weight: 900;
color: white;
}
.step h3 {
color: var(--accent-orange);
margin-bottom: 10px;
font-size: 1.5rem;
}
.feature-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
gap: 25px;
margin: 30px 0;
}
.feature-card {
background: var(--bg-secondary);
padding: 30px;
border-radius: 15px;
text-align: center;
transition: all 0.3s ease;
border: 2px solid transparent;
}
.feature-card:hover {
border-color: var(--accent-pink);
transform: translateY(-10px);
}
.feature-icon {
font-size: 3.5rem;
margin-bottom: 15px;
}
.feature-title {
font-weight: 600;
color: var(--accent-orange);
margin-bottom: 10px;
font-size: 1.3rem;
}
.demo-container {
background: var(--bg-secondary);
border-radius: 20px;
padding: 40px;
margin: 30px 0;
}
.memory-visualizer {
background: var(--bg-card);
border-radius: 15px;
padding: 30px;
margin: 30px 0;
border: 2px solid var(--accent-pink);
}
.memory-bar-container {
background: #1e1e1e;
border-radius: 10px;
height: 60px;
margin: 20px 0;
position: relative;
overflow: hidden;
}
.memory-bar {
height: 100%;
background: var(--gradient-memory);
transition: width 1s ease;
display: flex;
align-items: center;
justify-content: center;
color: white;
font-weight: 600;
font-size: 1.1rem;
}
.memory-controls {
display: flex;
gap: 10px;
margin-top: 20px;
flex-wrap: wrap;
}
.memory-btn {
background: var(--gradient-memory);
color: white;
border: none;
padding: 12px 24px;
border-radius: 10px;
font-size: 1rem;
font-weight: 600;
cursor: pointer;
transition: all 0.3s ease;
}
.memory-btn:hover {
transform: scale(1.05);
box-shadow: 0 5px 20px rgba(236, 72, 153, 0.4);
}
.terminal {
background: #1e1e1e;
border-radius: 15px;
padding: 20px;
font-family: 'Fira Code', monospace;
min-height: 300px;
margin: 20px 0;
overflow-y: auto;
max-height: 500px;
}
.terminal-line {
margin: 10px 0;
}
.terminal-prompt {
color: var(--accent-green);
}
.demo-button {
background: var(--gradient-memory);
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(236, 72, 153, 0.4);
}
.size-comparison {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
gap: 20px;
margin: 30px 0;
}
.size-item {
background: var(--bg-secondary);
padding: 20px;
border-radius: 15px;
text-align: center;
border: 2px solid transparent;
transition: all 0.3s ease;
}
.size-item:hover {
border-color: var(--accent-pink);
transform: scale(1.05);
}
.size-value {
font-size: 2rem;
font-weight: 700;
color: var(--accent-orange);
margin: 10px 0;
}
.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-memory);
color: white;
}
.tab-content {
display: none;
}
.tab-content.active {
display: block;
}
.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;
}
.tip, .warning, .success, .info {
padding: 20px;
border-radius: 10px;
margin: 20px 0;
}
.tip {
background: rgba(59, 130, 246, 0.1);
border-left: 4px solid var(--accent-blue);
}
.tip::before { content: '๐ก '; font-size: 1.5rem; }
.warning {
background: rgba(239, 68, 68, 0.1);
border-left: 4px solid var(--accent-red);
}
.warning::before { content: 'โ ๏ธ '; font-size: 1.5rem; }
.success {
background: rgba(16, 185, 129, 0.1);
border-left: 4px solid var(--accent-green);
}
.success::before { content: 'โ
'; font-size: 1.5rem; }
.info {
background: rgba(236, 72, 153, 0.1);
border-left: 4px solid var(--accent-pink);
}
.info::before { content: '๐ '; font-size: 1.5rem; }
.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;
font-size: 1.3rem;
}
.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: var(--accent-red);
background: rgba(239, 68, 68, 0.1);
}
.quiz-feedback {
margin-top: 15px;
padding: 15px;
border-radius: 10px;
display: none;
}
.quiz-feedback.show {
display: block;
}
.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 var(--accent-red);
}
.cheat-sheet {
background: var(--gradient-memory);
border-radius: 20px;
padding: 40px;
margin: 30px 0;
color: white;
}
.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.15);
backdrop-filter: blur(10px);
padding: 20px;
border-radius: 15px;
border: 1px solid rgba(255, 255, 255, 0.2);
}
.cheat-item h4 {
color: white;
margin-bottom: 10px;
font-weight: 600;
}
.cheat-item code {
background: rgba(0, 0, 0, 0.3);
padding: 4px 8px;
border-radius: 5px;
font-size: 0.9rem;
color: white;
}
.highlight {
color: var(--accent-yellow);
font-weight: 600;
}
.footer {
text-align: center;
padding: 40px 20px;
background: var(--bg-secondary);
margin-top: 80px;
border-radius: 20px;
}
.footer p {
color: var(--text-secondary);
margin: 10px 0;
}
.badge {
display: inline-block;
padding: 6px 12px;
background: var(--gradient-memory);
border-radius: 20px;
font-size: 0.85rem;
font-weight: 600;
margin: 5px;
}
.confetti {
position: fixed;
width: 10px;
height: 10px;
background: var(--accent-pink);
animation: confetti-fall 3s linear forwards;
z-index: 9999;
}
@keyframes confetti-fall {
to {
transform: translateY(100vh) rotate(360deg);
opacity: 0;
}
}
@media (max-width: 768px) {
.hero h1 { font-size: 2rem; }
.command-display { font-size: 0.85rem; padding: 15px 20px; }
.section-title { font-size: 1.8rem; }
.card { padding: 25px; }
.step { padding-left: 80px; }
.step::before { width: 50px; height: 50px; font-size: 1.5rem; }
}
</style>
</head>
<body>
<div class="progress-container">
<div class="progress-bar" id="progressBar"></div>
</div>
<div class="hero">
<div class="hero-content">
<div class="memory-icon">๐ง </div>
<h1>Master Memory Management!</h1>
<div class="command-display">node --max-old-space-size=4096 app.js</div>
<p>Boost your Node.js heap memory to 4GB! ๐</p>
</div>
</div>
<div class="container">
<!-- What Is It -->
<section class="section">
<h2 class="section-title">๐ค What Is This Command?</h2>
<div class="card">
<p style="font-size: 1.2rem; margin-bottom: 20px;">
This command tells Node.js to increase the <span class="highlight">maximum heap memory</span> available to your application from the default ~1.5GB to <strong>4GB</strong>! ๐ง
</p>
<p style="margin-bottom: 20px;">
Think of it like upgrading your app's RAM! ๐พ By default, Node.js limits how much memory your JavaScript code can use. This flag removes those training wheels and gives your app more breathing room!
</p>
<div class="info">
<strong>Breaking It Down:</strong>
<ul style="margin-left: 30px; margin-top: 10px; line-height: 2;">
<li><code>node</code> - The Node.js runtime</li>
<li><code class="code-flag">--max-old-space-size=4096</code> - Sets max heap to 4096 MB (4 GB)</li>
<li><code>app.js</code> - Your JavaScript application</li>
<li>The number is in <strong>megabytes</strong> (MB)</li>
</ul>
</div>
<div style="margin-top: 30px;">
<h3 style="color: var(--accent-pink); margin-bottom: 15px;">What's "Old Space"? ๐</h3>
<p>"Old space" is where V8 (Node's JavaScript engine) stores long-lived objects. It's the main memory area that grows as your app runs. When it fills up, you get the dreaded "JavaScript heap out of memory" error!</p>
</div>
</div>
</section>
<!-- Memory Visualizer -->
<section class="section">
<h2 class="section-title">๐ Interactive Memory Visualizer</h2>
<div class="demo-container">
<div class="memory-visualizer">
<h3 style="margin-bottom: 15px;">See Memory Limits in Action! ๐ฎ</h3>
<div style="margin-bottom: 20px;">
<strong>Current Setting:</strong> <span id="currentSize" style="color: var(--accent-orange); font-size: 1.2rem;">1536 MB</span>
</div>
<div class="memory-bar-container">
<div class="memory-bar" id="memoryBar" style="width: 50%;">50% Used</div>
</div>
<div class="memory-controls">
<button class="memory-btn" onclick="setMemory(512)">512 MB (Tiny)</button>
<button class="memory-btn" onclick="setMemory(1536)">1536 MB (Default)</button>
<button class="memory-btn" onclick="setMemory(4096)">4096 MB (4 GB)</button>
<button class="memory-btn" onclick="setMemory(8192)">8192 MB (8 GB)</button>
</div>
<div id="memoryInfo" style="margin-top: 20px; padding: 15px; background: rgba(0,0,0,0.3); border-radius: 10px;">
<strong>Info:</strong> Default Node.js heap size is ~1536 MB
</div>
</div>
</div>
</section>
<!-- Why Use It -->
<section class="section">
<h2 class="section-title">โจ Why Increase Memory?</h2>
<div class="card">
<div class="feature-grid">
<div class="feature-card">
<div class="feature-icon">๐ฆ</div>
<div class="feature-title">Large Datasets</div>
<p style="color: var(--text-secondary);">Process big files!</p>
</div>
<div class="feature-card">
<div class="feature-icon">๐จ</div>
<div class="feature-title">Image Processing</div>
<p style="color: var(--text-secondary);">Handle high-res images!</p>
</div>
<div class="feature-card">
<div class="feature-icon">๐๏ธ</div>
<div class="feature-title">Build Tools</div>
<p style="color: var(--text-secondary);">Webpack, Vite, etc!</p>
</div>
<div class="feature-card">
<div class="feature-icon">๐</div>
<div class="feature-title">Data Analysis</div>
<p style="color: var(--text-secondary);">Crunch numbers!</p>
</div>
<div class="feature-card">
<div class="feature-icon">๐งช</div>
<div class="feature-title">Testing</div>
<p style="color: var(--text-secondary);">Run large test suites!</p>
</div>
<div class="feature-card">
<div class="feature-icon">๐ซ</div>
<div class="feature-title">Prevent Crashes</div>
<p style="color: var(--text-secondary);">Avoid OOM errors!</p>
</div>
</div>
</div>
</section>
<!-- Size Comparison -->
<section class="section">
<h2 class="section-title">๐ Memory Size Comparison</h2>
<div class="card">
<div class="size-comparison">
<div class="size-item">
<div>โ ๏ธ Too Small</div>
<div class="size-value">512 MB</div>
<div style="color: var(--text-secondary); font-size: 0.9rem;">May crash easily</div>
</div>
<div class="size-item">
<div>๐ Default</div>
<div class="size-value">~1.5 GB</div>
<div style="color: var(--text-secondary); font-size: 0.9rem;">Standard limit</div>
</div>
<div class="size-item">
<div>โ
Recommended</div>
<div class="size-value">4 GB</div>
<div style="color: var(--text-secondary); font-size: 0.9rem;">Good for most apps</div>
</div>
<div class="size-item">
<div>๐ Large Apps</div>
<div class="size-value">8 GB+</div>
<div style="color: var(--text-secondary); font-size: 0.9rem;">Heavy workloads</div>
</div>
</div>
</div>
</section>
<!-- How It Works -->
<section class="section">
<h2 class="section-title">โ๏ธ How Does It Work?</h2>
<div class="card">
<div class="steps">
<div class="step">
<h3>Step 1: Flag Parsed</h3>
<p>Node.js reads the --max-old-space-size flag at startup.</p>
</div>
<div class="step">
<h3>Step 2: V8 Configured</h3>
<p>The V8 JavaScript engine sets the heap memory limit.</p>
</div>
<div class="step">
<h3>Step 3: Memory Allocated</h3>
<p>Operating system reserves memory for Node.js process.</p>
</div>
<div class="step">
<h3>Step 4: App Runs</h3>
<p>Your application can now use up to 4GB of heap memory.</p>
</div>
<div class="step">
<h3>Step 5: Garbage Collection</h3>
<p>V8 manages memory, cleaning up unused objects automatically.</p>
</div>
<div class="step">
<h3>Step 6: Monitoring</h3>
<p>Track usage with process.memoryUsage() to avoid hitting limits! ๐</p>
</div>
</div>
</div>
</section>
<!-- Live Demo -->
<section class="section">
<h2 class="section-title">๐ฎ Command Examples</h2>
<div class="demo-container">
<h3 style="margin-bottom: 20px; font-size: 1.5rem;">See Different Scenarios! ๐</h3>
<div style="margin-top: 30px;">
<button class="demo-button" onclick="simulateDefault()">
<span>๐</span>
<span>Default Memory</span>
</button>
<button class="demo-button" onclick="simulateIncreased()">
<span>๐</span>
<span>Increased to 4GB</span>
</button>
<button class="demo-button" onclick="simulateCrash()">
<span>๐ฅ</span>
<span>Out of Memory</span>
</button>
</div>
<div class="terminal" id="terminal">
<div class="terminal-line">
<span class="terminal-prompt">$</span>
<span style="color: var(--text-secondary);"> Ready to explore memory limits...</span>
</div>
</div>
</div>
</section>
<!-- Code Breakdown -->
<section class="section">
<h2 class="section-title">๐ป Usage Examples</h2>
<div class="card">
<div class="tabs">
<button class="tab active" onclick="switchTab('basic')">Basic Usage</button>
<button class="tab" onclick="switchTab('sizes')">Different Sizes</button>
<button class="tab" onclick="switchTab('scripts')">npm Scripts</button>
<button class="tab" onclick="switchTab('monitoring')">Monitor Memory</button>
</div>
<div id="basic" class="tab-content active">
<h3 style="color: var(--accent-pink); margin-bottom: 15px;">Basic Memory Configuration</h3>
<div class="code-block">
<div class="code-header">
<div class="terminal-dots">
<div class="terminal-dot dot-red"></div>
<div class="terminal-dot dot-yellow"></div>
<div class="terminal-dot dot-green"></div>
</div>
<button class="copy-btn" onclick="copyCode('basic-code')">๐ Copy</button>
</div>
<pre><code id="basic-code"><span class="code-comment"># Set heap to 4GB (4096 MB)</span>
node --max-old-space-size=4096 app.js
<span class="code-comment"># Set heap to 8GB</span>
node --max-old-space-size=8192 app.js
<span class="code-comment"># Check current memory usage in your code</span>
<span class="code-keyword">const</span> used = process.memoryUsage();
console.log(<span class="code-string">`Heap Used: ${Math.round(used.heapUsed / 1024 / 1024)} MB`</span>);</code></pre>
</div>
<div class="success" style="margin-top: 15px;">
<strong>Result:</strong> Your app can now use up to 4GB of memory!
</div>
</div>
<div id="sizes" class="tab-content">
<h3 style="color: var(--accent-pink); margin-bottom: 15px;">Common Memory Sizes</h3>
<div class="code-block">
<div class="code-header">
<div class="terminal-dots">
<div class="terminal-dot dot-red"></div>
<div class="terminal-dot dot-yellow"></div>
<div class="terminal-dot dot-green"></div>
</div>
<button class="copy-btn" onclick="copyCode('sizes-code')">๐ Copy</button>
</div>
<pre><code id="sizes-code"><span class="code-comment"># Small apps (512 MB)</span>
node --max-old-space-size=512 app.js
<span class="code-comment"># Default-ish (1.5 GB)</span>
node --max-old-space-size=1536 app.js
<span class="code-comment"># Medium apps (2 GB)</span>
node --max-old-space-size=2048 app.js
<span class="code-comment"># Large apps (4 GB) - Recommended</span>
node --max-old-space-size=4096 app.js
<span class="code-comment"># Very large apps (8 GB)</span>
node --max-old-space-size=8192 app.js
<span class="code-comment"># Maximum practical (16 GB)</span>
node --max-old-space-size=16384 app.js</code></pre>
</div>
<div class="tip" style="margin-top: 15px;">
<strong>Pro Tip:</strong> Start with 4GB and adjust based on your needs!
</div>
</div>
<div id="scripts" class="tab-content">
<h3 style="color: var(--accent-pink); margin-bottom: 15px;">npm Scripts Configuration</h3>
<div class="code-block">
<div class="code-header">
<div class="terminal-dots">
<div class="terminal-dot dot-red"></div>
<div class="terminal-dot dot-yellow"></div>
<div class="terminal-dot dot-green"></div>
</div>
<button class="copy-btn" onclick="copyCode('scripts-code')">๐ Copy</button>
</div>
<pre><code id="scripts-code"><span class="code-comment">// package.json</span>
{
<span class="code-string">"scripts"</span>: {
<span class="code-string">"start"</span>: <span class="code-string">"node --max-old-space-size=4096 app.js"</span>,
<span class="code-string">"build"</span>: <span class="code-string">"node --max-old-space-size=8192 build.js"</span>,
<span class="code-string">"test"</span>: <span class="code-string">"node --max-old-space-size=4096 node_modules/.bin/jest"</span>
}
}
<span class="code-comment"># Run with npm</span>
npm start
npm run build</code></pre>
</div>
<div class="info" style="margin-top: 15px;">
<strong>Note:</strong> This applies to all npm scripts that run Node.js!
</div>
</div>
<div id="monitoring" class="tab-content">
<h3 style="color: var(--accent-pink); margin-bottom: 15px;">Monitor Memory Usage</h3>
<div class="code-block">
<div class="code-header">
<div class="terminal-dots">
<div class="terminal-dot dot-red"></div>
<div class="terminal-dot dot-yellow"></div>
<div class="terminal-dot dot-green"></div>
</div>
<button class="copy-btn" onclick="copyCode('monitoring-code')">๐ Copy</button>
</div>
<pre><code id="monitoring-code"><span class="code-comment">// Check memory usage</span>
<span class="code-keyword">function</span> checkMemory() {
<span class="code-keyword">const</span> usage = process.memoryUsage();
console.log({
heapUsed: <span class="code-string">`${Math.round(usage.heapUsed / 1024 / 1024)} MB`</span>,
heapTotal: <span class="code-string">`${Math.round(usage.heapTotal / 1024 / 1024)} MB`</span>,
external: <span class="code-string">`${Math.round(usage.external / 1024 / 1024)} MB`</span>
});
}
<span class="code-comment">// Monitor every 5 seconds</span>
setInterval(checkMemory, <span class="code-number">5000</span>);
<span class="code-comment">// Force garbage collection (requires --expose-gc flag)</span>
<span class="code-keyword">if</span> (global.gc) {
global.gc();
console.log(<span class="code-string">'Garbage collection triggered'</span>);
}</code></pre>
</div>
</div>
</div>
</section>
<!-- Common Mistakes -->
<section class="section">
<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. Setting Memory Too High</strong></span>
<span class="accordion-icon">โผ</span>
</div>
<div class="accordion-content">
<div class="accordion-body">
<div class="warning">
<strong>Problem:</strong> Setting memory higher than available system RAM!
</div>
<div class="success" style="margin-top: 15px;">
<strong>Solution:</strong> Leave at least 2GB for OS. If you have 8GB RAM, use max 6GB for Node.js.
</div>
</div>
</div>
</div>
<div class="accordion-item">
<div class="accordion-header" onclick="toggleAccordion(this)">
<span><strong>2. Using Wrong Units</strong></span>
<span class="accordion-icon">โผ</span>
</div>
<div class="accordion-content">
<div class="accordion-body">
<div class="warning">
<strong>Problem:</strong> Confusing MB with GB! Using 4 instead of 4096!
</div>
<div class="success" style="margin-top: 15px;">
<strong>Solution:</strong> Value is in MB. 1 GB = 1024 MB. So 4 GB = 4096 MB.
</div>
</div>
</div>
</div>
<div class="accordion-item">
<div class="accordion-header" onclick="toggleAccordion(this)">
<span><strong>3. Not Fixing Memory Leaks</strong></span>
<span class="accordion-icon">โผ</span>
</div>
<div class="accordion-content">
<div class="accordion-body">
<div class="warning">
<strong>Problem:</strong> Increasing memory to hide memory leaks!
</div>
<div class="success" style="margin-top: 15px;">
<strong>Solution:</strong> Use profiling tools to find and fix leaks. Memory increase is temporary!
</div>
</div>
</div>
</div>
</div>
</div>
</section>
<!-- Pro Tips -->
<section class="section">
<h2 class="section-title">๐ Pro Tips</h2>
<div class="card">
<div class="tip">
<strong>Start conservative</strong> - Begin with 4GB and increase only if needed!
</div>
<div class="tip">
<strong>Monitor in production</strong> - Use <code>process.memoryUsage()</code> to track actual usage!
</div>
<div class="tip">
<strong>Environment variables</strong> - Set via <code>NODE_OPTIONS="--max-old-space-size=4096"</code> for all Node processes!
</div>
<div class="tip">
<strong>Docker containers</strong> - Ensure container memory limit is higher than Node.js heap!
</div>
<div class="tip">
<strong>Profile first</strong> - Use Chrome DevTools or clinic.js to identify actual memory needs!
</div>
<div class="tip">
<strong>Garbage collection</strong> - Use <code>--expose-gc</code> flag to manually trigger GC for testing!
</div>
</div>
</section>
<!-- Quiz -->
<section class="section">
<h2 class="section-title">๐ฏ Knowledge Check Quiz</h2>
<div class="quiz-container">
<p style="margin-bottom: 30px; font-size: 1.1rem;">Test your understanding! ๐ง </p>
<div class="quiz-question">
<h3>Question 1: What units does --max-old-space-size use?</h3>
<div class="quiz-options">
<div class="quiz-option" onclick="checkAnswer(this, false, 1)">A) Gigabytes (GB)</div>
<div class="quiz-option" onclick="checkAnswer(this, true, 1)">B) Megabytes (MB)</div>
<div class="quiz-option" onclick="checkAnswer(this, false, 1)">C) Kilobytes (KB)</div>
</div>
<div class="quiz-feedback" id="feedback1"></div>
</div>
<div class="quiz-question">
<h3>Question 2: What's the default Node.js heap size?</h3>
<div class="quiz-options">
<div class="quiz-option" onclick="checkAnswer(this, false, 2)">A) 512 MB</div>
<div class="quiz-option" onclick="checkAnswer(this, true, 2)">B) ~1.5 GB (1536 MB)</div>
<div class="quiz-option" onclick="checkAnswer(this, false, 2)">C) 4 GB</div>
</div>
<div class="quiz-feedback" id="feedback2"></div>
</div>
<div class="quiz-question">
<h3>Question 3: How to set 8GB of heap memory?</h3>
<div class="quiz-options">
<div class="quiz-option" onclick="checkAnswer(this, false, 3)">A) --max-old-space-size=8</div>
<div class="quiz-option" onclick="checkAnswer(this, true, 3)">B) --max-old-space-size=8192</div>
<div class="quiz-option" onclick="checkAnswer(this, false, 3)">C) --max-old-space-size=8000</div>
</div>
<div class="quiz-feedback" id="feedback3"></div>
</div>
<div id="quizScore" style="margin-top: 30px; padding: 20px; background: var(--bg-secondary); border-radius: 12px; display: none;">
<h3 style="color: var(--accent-green); font-size: 1.5rem;">๐ Quiz Complete!</h3>
<p id="scoreText" style="font-size: 1.2rem; margin-top: 10px;"></p>
</div>
</div>
</section>
<!-- Summary Card -->
<section class="section">
<h2 class="section-title">๐ Quick Reference</h2>
<div class="cheat-sheet">
<h3 style="margin-bottom: 20px; font-size: 2rem;">Memory Management Cheat Sheet! ๐</h3>
<div class="cheat-grid">
<div class="cheat-item">
<h4>๐ง Basic Command</h4>
<p><code>node --max-old-space-size=4096 app.js</code></p>
<p style="font-size: 0.85rem; margin-top: 5px;">Set to 4GB</p>
</div>
<div class="cheat-item">
<h4>๐ Units</h4>
<p>Value in MB (megabytes)</p>
<p style="font-size: 0.85rem; margin-top: 5px;">1 GB = 1024 MB</p>
</div>
<div class="cheat-item">
<h4>๐ Default</h4>
<p>~1536 MB (~1.5 GB)</p>
<p style="font-size: 0.85rem; margin-top: 5px;">Standard limit</p>
</div>
<div class="cheat-item">
<h4>โ
Recommended</h4>
<p>4096 MB (4 GB)</p>
<p style="font-size: 0.85rem; margin-top: 5px;">Good for most apps</p>
</div>
<div class="cheat-item">
<h4>๐ฆ npm Script</h4>
<p><code>"start": "node --max-old-space-size=4096 app.js"</code></p>
<p style="font-size: 0.85rem; margin-top: 5px;">In package.json</p>
</div>
<div class="cheat-item">
<h4>๐ Environment</h4>
<p><code>NODE_OPTIONS="--max-old-space-size=4096"</code></p>
<p style="font-size: 0.85rem; margin-top: 5px;">Global setting</p>
</div>
<div class="cheat-item">
<h4>๐ Monitor</h4>
<p><code>process.memoryUsage()</code></p>
<p style="font-size: 0.85rem; margin-top: 5px;">Check usage</p>
</div>
<div class="cheat-item">
<h4>โ ๏ธ Warning</h4>
<p>Leave RAM for OS!</p>
<p style="font-size: 0.85rem; margin-top: 5px;">Don't use all RAM</p>
</div>
</div>
</div>
</section>
<!-- Footer -->
<div class="footer">
<h2 style="font-size: 2rem; margin-bottom: 20px; color: var(--accent-pink);">๐ Congratulations!</h2>
<p style="font-size: 1.2rem; margin-bottom: 20px;">You now understand <strong>Node.js memory management</strong>! ๐</p>
<div style="margin: 30px 0;">
<span class="badge">๐ง Memory Master</span>
<span class="badge">โก Performance Pro</span>
<span class="badge">๐ Node.js Expert</span>
</div>
<p style="color: var(--text-secondary); margin-top: 30px;">Generated by <strong>AI Prompt Dictionary</strong> ๐ค</p>
<p style="color: var(--text-secondary); font-size: 0.9rem;">Made with โค๏ธ for developers learning Node.js</p>
</div>
</div>
<script>
// Progress bar
window.addEventListener('scroll', () => {
const winScroll = document.body.scrollTop || document.documentElement.scrollTop;
const height = document.documentElement.scrollHeight - document.documentElement.clientHeight;
const scrolled = (winScroll / height) * 100;
document.getElementById('progressBar').style.width = scrolled + '%';
});
// Copy to clipboard
function copyCode(codeId) {
const code = document.getElementById(codeId).innerText;
navigator.clipboard.writeText(code).then(() => {
event.target.textContent = 'โ
Copied!';
event.target.classList.add('copied');
setTimeout(() => {
event.target.textContent = '๐ Copy';
event.target.classList.remove('copied');
}, 2000);
});
}
// Tab switching
function switchTab(tabName) {
document.querySelectorAll('.tab-content').forEach(c => c.classList.remove('active'));
document.querySelectorAll('.tab').forEach(t => t.classList.remove('active'));
document.getElementById(tabName).classList.add('active');
event.target.classList.add('active');
}
// Accordion toggle
function toggleAccordion(header) {
const content = header.nextElementSibling;
const icon = header.querySelector('.accordion-icon');
content.classList.toggle('active');
icon.classList.toggle('active');
}
// Memory visualizer
function setMemory(size) {
const bar = document.getElementById('memoryBar');
const sizeText = document.getElementById('currentSize');
const info = document.getElementById('memoryInfo');
sizeText.textContent = size + ' MB';
// Simulate memory usage (50% of max)
const percentage = 50;
bar.style.width = percentage + '%';
bar.textContent = percentage + '% Used';
let message = '';
if (size < 1024) {
message = 'โ ๏ธ Very small! May cause crashes for large apps.';
} else if (size === 1536) {
message = '๐ This is the default Node.js heap size.';
} else if (size === 4096) {
message = 'โ
Recommended size for most applications!';
} else if (size >= 8192) {
message = '๐ Large heap! Good for heavy workloads.';
}
info.innerHTML = '<strong>Info:</strong> ' + message;
createConfetti();
}
// Simulate default
function simulateDefault() {
const terminal = document.getElementById('terminal');
terminal.innerHTML = '<div class="terminal-line"><span class="terminal-prompt">$</span> node app.js</div>';
setTimeout(() => {
terminal.innerHTML += '<div style="color: var(--accent-cyan); margin-top: 10px;">Starting application with default memory...</div>';
terminal.innerHTML += '<div style="color: var(--text-secondary); margin-top: 10px;">Heap limit: ~1536 MB</div>';
terminal.innerHTML += '<div style="color: var(--accent-green); margin-top: 10px;">โ
App running normally</div>';
}, 500);
}
// Simulate increased
function simulateIncreased() {
const terminal = document.getElementById('terminal');
terminal.innerHTML = '<div class="terminal-line"><span class="terminal-prompt">$</span> node --max-old-space-size=4096 app.js</div>';
setTimeout(() => {
terminal.innerHTML += '<div style="color: var(--accent-cyan); margin-top: 10px;">Starting with increased memory...</div>';
terminal.innerHTML += '<div style="color: var(--text-secondary); margin-top: 10px;">Heap limit: 4096 MB (4 GB)</div>';
terminal.innerHTML += '<div style="color: var(--accent-green); margin-top: 10px;">โ
Processing large dataset...</div>';
terminal.innerHTML += '<div style="color: var(--accent-green); margin-top: 5px;">โ
Memory sufficient - no crashes!</div>';
createConfetti();
}, 500);
}
// Simulate crash
function simulateCrash() {
const terminal = document.getElementById('terminal');
terminal.innerHTML = '<div class="terminal-line"><span class="terminal-prompt">$</span> node app.js</div>';
setTimeout(() => {
terminal.innerHTML += '<div style="color: var(--accent-cyan); margin-top: 10px;">Processing large file...</div>';
terminal.innerHTML += '<div style="color: var(--accent-yellow); margin-top: 10px;">Memory usage: 1200 MB...</div>';
terminal.innerHTML += '<div style="color: var(--accent-yellow); margin-top: 5px;">Memory usage: 1400 MB...</div>';
}, 500);
setTimeout(() => {
terminal.innerHTML += '<div style="color: var(--accent-red); margin-top: 10px; font-weight: 600;">๐ฅ FATAL ERROR: JavaScript heap out of memory!</div>';
terminal.innerHTML += '<div style="color: var(--text-secondary); margin-top: 15px;">Solution: Use --max-old-space-size=4096</div>';
}, 1500);
}
// Quiz system
let quizScore = 0;
let questionsAnswered = 0;
function checkAnswer(element, isCorrect, questionNum) {
const options = element.parentElement.querySelectorAll('.quiz-option');
options.forEach(opt => opt.style.pointerEvents = 'none');
const feedback = document.getElementById('feedback' + questionNum);
if (isCorrect) {
element.classList.add('correct');
feedback.className = 'quiz-feedback correct show';
feedback.innerHTML = '<strong>๐ Correct!</strong> Great job!';
quizScore++;
createConfetti();
} else {
element.classList.add('incorrect');
feedback.className = 'quiz-feedback incorrect show';
feedback.innerHTML = '<strong>โ Not quite!</strong> Review the material and try again!';
}
questionsAnswered++;
if (questionsAnswered === 3) {
setTimeout(() => {
document.getElementById('quizScore').style.display = 'block';
document.getElementById('scoreText').textContent = `You scored ${quizScore}/3! ${quizScore === 3 ? '๐ Perfect!' : quizScore === 2 ? '๐ Good job!' : '๐ช Keep learning!'}`;
}, 1000);
}
}
// Confetti animation
function createConfetti() {
const colors = ['#ec4899', '#fb923c', '#3b82f6', '#10b981', '#a855f7'];
for (let i = 0; i < 50; i++) {
const confetti = document.createElement('div');
confetti.className = 'confetti';
confetti.style.left = Math.random() * window.innerWidth + 'px';
confetti.style.background = colors[Math.floor(Math.random() * colors.length)];
confetti.style.animationDuration = (2 + Math.random() * 2) + 's';
document.body.appendChild(confetti);
setTimeout(() => confetti.remove(), 4000);
}
}
</script>
</body>
</html>
Live Preview