Show the current logged-in npm user
📦 Node.js-> Command Line
✨ The Prompt Phrase
npm whoami
💻 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>Show the current logged-in npm user - 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-npm: #cb3837;
--text-primary: #f8fafc;
--text-secondary: #94a3b8;
--gradient-npm: linear-gradient(135deg, #cb3837 0%, #ef4444 100%);
--gradient-identity: linear-gradient(135deg, #a855f7 0%, #3b82f6 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-identity);
width: 0%;
transition: width 0.3s ease;
}
.hero {
text-align: center;
padding: 100px 20px;
background: var(--gradient-identity);
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;
}
.whoami-icon {
font-size: 5rem;
margin-bottom: 20px;
animation: whoamiSpin 4s ease-in-out infinite;
}
@keyframes whoamiSpin {
0%, 100% { transform: scale(1) rotate(0deg); }
25% { transform: scale(1.1) rotate(-10deg); }
75% { transform: scale(1.1) rotate(10deg); }
}
.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: 2rem;
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-identity);
-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-npm { color: #cb3837; font-weight: 600; }
.code-output { color: #4ec9b0; }
.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-identity);
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-purple);
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-purple);
transform: translateY(-10px);
}
.feature-icon {
font-size: 3.5rem;
margin-bottom: 15px;
}
.feature-title {
font-weight: 600;
color: var(--accent-purple);
margin-bottom: 10px;
font-size: 1.3rem;
}
.demo-container {
background: var(--bg-secondary);
border-radius: 20px;
padding: 40px;
margin: 30px 0;
}
.whoami-simulator {
background: var(--bg-card);
border-radius: 15px;
padding: 30px;
margin: 30px 0;
border: 2px solid var(--accent-purple);
}
.user-card {
background: var(--gradient-identity);
border-radius: 15px;
padding: 30px;
text-align: center;
margin: 20px 0;
}
.user-avatar {
width: 100px;
height: 100px;
background: white;
border-radius: 50%;
margin: 0 auto 20px;
display: flex;
align-items: center;
justify-content: center;
font-size: 3rem;
}
.user-name {
font-size: 2rem;
font-weight: 700;
color: white;
margin-bottom: 10px;
}
.terminal {
background: #1e1e1e;
border-radius: 15px;
padding: 20px;
font-family: 'Fira Code', monospace;
min-height: 200px;
margin: 20px 0;
overflow-y: auto;
max-height: 500px;
}
.terminal-line {
margin: 10px 0;
}
.terminal-prompt {
color: var(--accent-green);
}
.terminal-success {
color: var(--accent-green);
font-weight: 600;
}
.terminal-error {
color: var(--accent-red);
}
.demo-button {
background: var(--gradient-identity);
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);
}
.comparison-table {
width: 100%;
border-collapse: collapse;
margin: 30px 0;
}
.comparison-table th,
.comparison-table td {
padding: 20px;
text-align: left;
border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}
.comparison-table th {
background: var(--bg-secondary);
color: var(--accent-purple);
font-weight: 600;
}
.comparison-table tr:hover {
background: var(--bg-secondary);
}
.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-identity);
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-identity);
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-identity);
border-radius: 20px;
font-size: 0.85rem;
font-weight: 600;
margin: 5px;
}
.confetti {
position: fixed;
width: 10px;
height: 10px;
background: var(--accent-purple);
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: 1.3rem; 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="whoami-icon">👤</div>
<h1>Master npm whoami!</h1>
<div class="command-display">npm whoami</div>
<p>Discover your npm identity! 🎭</p>
</div>
</div>
<div class="container">
<!-- What Is It -->
<section class="section">
<h2 class="section-title">🤔 What Is npm whoami?</h2>
<div class="card">
<p style="font-size: 1.2rem; margin-bottom: 20px;">
<code>npm whoami</code> is a <span class="highlight">simple command</span> that tells you which npm user account you're currently <strong>logged in as</strong> on your machine! 👤
</p>
<p style="margin-bottom: 20px;">
Think of it like checking your name tag! 🏷️ When you're at a conference (npm registry), you might forget which badge you're wearing. This command is like looking down at your badge to see "Hello, my name is..." - it shows your current npm username!
</p>
<div class="info">
<strong>Breaking It Down:</strong>
<ul style="margin-left: 30px; margin-top: 10px; line-height: 2;">
<li><code class="code-npm">npm</code> - Node Package Manager</li>
<li><code class="code-npm">whoami</code> - "Who am I?" - shows current user</li>
<li>Returns your npm username if logged in</li>
<li>Shows error if not authenticated</li>
<li>Super quick - no prompts or interactions needed!</li>
</ul>
</div>
<div style="margin-top: 30px;">
<h3 style="color: var(--accent-pink); margin-bottom: 15px;">Why "whoami"? 🔍</h3>
<p>The name comes from the Unix/Linux command <code>whoami</code> which shows your current username on the system. npm borrowed this naming convention - it's a developer-friendly way to check identity!</p>
</div>
</div>
</section>
<!-- Interactive Demo -->
<section class="section">
<h2 class="section-title">🎮 Try It Out!</h2>
<div class="demo-container">
<div class="whoami-simulator">
<h3 style="margin-bottom: 20px; text-align: center;">Who Are You? 🎭</h3>
<div class="user-card" id="userCard">
<div class="user-avatar">👤</div>
<div class="user-name" id="userName">Not Logged In</div>
<p style="color: rgba(255,255,255,0.8);">Click a demo below to see different scenarios!</p>
</div>
</div>
<div style="margin-top: 30px; text-align: center;">
<h4 style="margin-bottom: 15px;">Quick Demos:</h4>
<button class="demo-button" onclick="simulateLoggedIn()">
<span>✅</span>
<span>Logged In User</span>
</button>
<button class="demo-button" onclick="simulateNotLoggedIn()">
<span>❌</span>
<span>Not Logged In</span>
</button>
<button class="demo-button" onclick="simulateScoped()">
<span>🏢</span>
<span>Organization User</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 check identity...</span>
</div>
</div>
</div>
</section>
<!-- Why Use It -->
<section class="section">
<h2 class="section-title">✨ Why Use npm whoami?</h2>
<div class="card">
<div class="feature-grid">
<div class="feature-card">
<div class="feature-icon">✅</div>
<div class="feature-title">Verify Login</div>
<p style="color: var(--text-secondary);">Check if authenticated!</p>
</div>
<div class="feature-card">
<div class="feature-icon">👥</div>
<div class="feature-title">Multiple Accounts</div>
<p style="color: var(--text-secondary);">Know which account is active!</p>
</div>
<div class="feature-card">
<div class="feature-icon">🔍</div>
<div class="feature-title">Quick Check</div>
<p style="color: var(--text-secondary);">Instant identity verification!</p>
</div>
<div class="feature-card">
<div class="feature-icon">🤖</div>
<div class="feature-title">Script Validation</div>
<p style="color: var(--text-secondary);">Verify in automation!</p>
</div>
<div class="feature-card">
<div class="feature-icon">🛡️</div>
<div class="feature-title">Security</div>
<p style="color: var(--text-secondary);">Prevent wrong-account publishes!</p>
</div>
<div class="feature-card">
<div class="feature-icon">📝</div>
<div class="feature-title">Debugging</div>
<p style="color: var(--text-secondary);">Troubleshoot auth issues!</p>
</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: Command Executed</h3>
<p>You run <code>npm whoami</code> in your terminal.</p>
</div>
<div class="step">
<h3>Step 2: Token Lookup</h3>
<p>npm checks ~/.npmrc for authentication token.</p>
</div>
<div class="step">
<h3>Step 3: Registry Query</h3>
<p>Sends token to npm registry for validation.</p>
</div>
<div class="step">
<h3>Step 4: Username Retrieved</h3>
<p>Registry returns the username associated with token.</p>
</div>
<div class="step">
<h3>Step 5: Display Result</h3>
<p>Shows username in terminal (or error if not logged in).</p>
</div>
<div class="step">
<h3>Step 6: Exit</h3>
<p>Command completes instantly - no waiting! 🎉</p>
</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('scripts')">In Scripts</button>
<button class="tab" onclick="switchTab('comparison')">vs Other Commands</button>
<button class="tab" onclick="switchTab('automation')">Automation</button>
</div>
<div id="basic" class="tab-content active">
<h3 style="color: var(--accent-pink); margin-bottom: 15px;">Basic 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('basic-code')">📋 Copy</button>
</div>
<pre><code id="basic-code"><span class="code-comment"># Check who you're logged in as</span>
npm whoami
<span class="code-comment"># If logged in, output:</span>
<span class="code-output">john_developer</span>
<span class="code-comment"># If NOT logged in, output:</span>
<span class="code-comment">npm ERR! need auth This command requires you to be logged in.</span>
<span class="code-comment">npm ERR! need auth You need to authorize this machine using `npm login`</span></code></pre>
</div>
<div class="success" style="margin-top: 15px;">
<strong>Result:</strong> Instantly know your current npm identity!
</div>
</div>
<div id="scripts" class="tab-content">
<h3 style="color: var(--accent-pink); margin-bottom: 15px;">Using in Scripts</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"># Bash script to verify user before publishing</span>
#!/bin/bash
CURRENT_USER=$(npm whoami 2>/dev/null)
EXPECTED_USER="my-company-account"
if [ "$CURRENT_USER" != "$EXPECTED_USER" ]; then
echo "❌ Wrong account! You're logged in as: $CURRENT_USER"
echo "Expected: $EXPECTED_USER"
exit 1
fi
echo "✅ Correct account verified!"
npm publish
<span class="code-comment"># Node.js script</span>
const { execSync } = require('child_process');
try {
const username = execSync('npm whoami', { encoding: 'utf8' }).trim();
console.log(`Logged in as: ${username}`);
} catch (error) {
console.error('Not logged in to npm!');
process.exit(1);
}</code></pre>
</div>
<div class="tip" style="margin-top: 15px;">
<strong>Pro Tip:</strong> Use in pre-publish scripts to prevent accidental publishes from wrong accounts!
</div>
</div>
<div id="comparison" class="tab-content">
<h3 style="color: var(--accent-pink); margin-bottom: 15px;">Command Comparison</h3>
<table class="comparison-table">
<thead>
<tr>
<th>Command</th>
<th>What It Does</th>
<th>Output</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>npm whoami</code></td>
<td>Shows current username</td>
<td>username</td>
</tr>
<tr>
<td><code>npm profile get</code></td>
<td>Shows full profile details</td>
<td>JSON with name, email, etc.</td>
</tr>
<tr>
<td><code>npm config list</code></td>
<td>Shows all npm configuration</td>
<td>All config settings</td>
</tr>
<tr>
<td><code>npm login</code></td>
<td>Authenticates you</td>
<td>Interactive prompts</td>
</tr>
</tbody>
</table>
</div>
<div id="automation" class="tab-content">
<h3 style="color: var(--accent-pink); margin-bottom: 15px;">CI/CD Automation</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('automation-code')">📋 Copy</button>
</div>
<pre><code id="automation-code"><span class="code-comment"># GitHub Actions - verify npm auth</span>
- name: Verify npm authentication
run: |
npm whoami
if [ $? -ne 0 ]; then
echo "❌ Not authenticated with npm"
exit 1
fi
<span class="code-comment"># GitLab CI - check user before publish</span>
verify-npm-user:
script:
- NPM_USER=$(npm whoami)
- echo "Publishing as $NPM_USER"
- |
if [ "$NPM_USER" != "expected-user" ]; then
echo "Wrong npm user!"
exit 1
fi
<span class="code-comment"># package.json prepublish script</span>
{
"scripts": {
"prepublishOnly": "npm whoami || (echo 'Not logged in!' && exit 1)"
}
}</code></pre>
</div>
<div class="info" style="margin-top: 15px;">
<strong>Note:</strong> Always verify authentication in CI/CD before publishing!
</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. Expecting Interactive Output</strong></span>
<span class="accordion-icon">▼</span>
</div>
<div class="accordion-content">
<div class="accordion-body">
<div class="warning">
<strong>Problem:</strong> Expecting prompts or detailed information
</div>
<div class="success" style="margin-top: 15px;">
<strong>Solution:</strong> <code>npm whoami</code> just prints username - use <code>npm profile get</code> for details!
</div>
</div>
</div>
</div>
<div class="accordion-item">
<div class="accordion-header" onclick="toggleAccordion(this)">
<span><strong>2. Not Handling Errors in Scripts</strong></span>
<span class="accordion-icon">▼</span>
</div>
<div class="accordion-content">
<div class="accordion-body">
<div class="warning">
<strong>Problem:</strong> Script crashes when user not logged in
</div>
<div class="success" style="margin-top: 15px;">
<strong>Solution:</strong> Use <code>npm whoami 2>/dev/null || echo "not-logged-in"</code> to handle errors!
</div>
</div>
</div>
</div>
<div class="accordion-item">
<div class="accordion-header" onclick="toggleAccordion(this)">
<span><strong>3. Confusing with npm profile</strong></span>
<span class="accordion-icon">▼</span>
</div>
<div class="accordion-content">
<div class="accordion-body">
<div class="warning">
<strong>Problem:</strong> Using wrong command for detailed info
</div>
<div class="success" style="margin-top: 15px;">
<strong>Solution:</strong> <code>whoami</code> = username only, <code>profile get</code> = full details!
</div>
</div>
</div>
</div>
<div class="accordion-item">
<div class="accordion-header" onclick="toggleAccordion(this)">
<span><strong>4. Assuming Always Logged In</strong></span>
<span class="accordion-icon">▼</span>
</div>
<div class="accordion-content">
<div class="accordion-body">
<div class="warning">
<strong>Problem:</strong> Scripts fail on fresh machines
</div>
<div class="success" style="margin-top: 15px;">
<strong>Solution:</strong> Always check exit code or catch errors in automation!
</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>Pre-publish check</strong> - Add <code>npm whoami</code> to prepublishOnly script to verify identity!
</div>
<div class="tip">
<strong>Multiple accounts</strong> - Use before switching between personal/work accounts!
</div>
<div class="tip">
<strong>Shell alias</strong> - Create alias: <code>alias npmuser='npm whoami'</code> for quick checks!
</div>
<div class="tip">
<strong>CI/CD validation</strong> - Always verify authentication before publishing in pipelines!
</div>
<div class="tip">
<strong>Error handling</strong> - Capture output: <code>USER=$(npm whoami 2>/dev/null)</code> to avoid script crashes!
</div>
<div class="tip">
<strong>Quick debug</strong> - First command to run when npm publish fails mysteriously!
</div>
<div class="tip">
<strong>Team workflows</strong> - Document expected usernames in README for team projects!
</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 does npm whoami return?</h3>
<div class="quiz-options">
<div class="quiz-option" onclick="checkAnswer(this, false, 1)">A) Your full profile information</div>
<div class="quiz-option" onclick="checkAnswer(this, true, 1)">B) Just your npm username</div>
<div class="quiz-option" onclick="checkAnswer(this, false, 1)">C) Your email address</div>
</div>
<div class="quiz-feedback" id="feedback1"></div>
</div>
<div class="quiz-question">
<h3>Question 2: What happens if you're not logged in?</h3>
<div class="quiz-options">
<div class="quiz-option" onclick="checkAnswer(this, false, 2)">A) Returns "anonymous"</div>
<div class="quiz-option" onclick="checkAnswer(this, true, 2)">B) Shows an error message</div>
<div class="quiz-option" onclick="checkAnswer(this, false, 2)">C) Prompts you to login</div>
</div>
<div class="quiz-feedback" id="feedback2"></div>
</div>
<div class="quiz-question">
<h3>Question 3: When is npm whoami most useful?</h3>
<div class="quiz-options">
<div class="quiz-option" onclick="checkAnswer(this, false, 3)">A) When installing packages</div>
<div class="quiz-option" onclick="checkAnswer(this, true, 3)">B) Before publishing or verifying identity</div>
<div class="quiz-option" onclick="checkAnswer(this, false, 3)">C) When updating npm</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;">npm whoami Cheat Sheet! 🔖</h3>
<div class="cheat-grid">
<div class="cheat-item">
<h4>👤 Basic Command</h4>
<p><code>npm whoami</code></p>
<p style="font-size: 0.85rem; margin-top: 5px;">Show current user</p>
</div>
<div class="cheat-item">
<h4>✅ Logged In</h4>
<p>Returns: username</p>
<p style="font-size: 0.85rem; margin-top: 5px;">Just the username</p>
</div>
<div class="cheat-item">
<h4>❌ Not Logged In</h4>
<p>Error: need auth</p>
<p style="font-size: 0.85rem; margin-top: 5px;">Exit code 1</p>
</div>
<div class="cheat-item">
<h4>🔍 In Scripts</h4>
<p><code>$(npm whoami)</code></p>
<p style="font-size: 0.85rem; margin-top: 5px;">Capture output</p>
</div>
<div class="cheat-item">
<h4>🛡️ Error Handling</h4>
<p><code>npm whoami 2>/dev/null</code></p>
<p style="font-size: 0.85rem; margin-top: 5px;">Suppress errors</p>
</div>
<div class="cheat-item">
<h4>📊 Full Profile</h4>
<p><code>npm profile get</code></p>
<p style="font-size: 0.85rem; margin-top: 5px;">More details</p>
</div>
<div class="cheat-item">
<h4>⚡ Speed</h4>
<p>Instant response</p>
<p style="font-size: 0.85rem; margin-top: 5px;">No waiting</p>
</div>
<div class="cheat-item">
<h4>🎯 Use Case</h4>
<p>Verify before publish</p>
<p style="font-size: 0.85rem; margin-top: 5px;">Check identity</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>npm whoami</strong>! 🚀</p>
<div style="margin: 30px 0;">
<span class="badge">👤 Identity Expert</span>
<span class="badge">✅ Verification Pro</span>
<span class="badge">🚀 npm Master</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 npm</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');
}
// Simulate logged in
function simulateLoggedIn() {
const terminal = document.getElementById('terminal');
const userCard = document.getElementById('userCard');
const userName = document.getElementById('userName');
terminal.innerHTML = '<div class="terminal-line"><span class="terminal-prompt">$</span> npm whoami</div>';
setTimeout(() => {
terminal.innerHTML += '<div class="terminal-success" style="margin-top: 10px;">john_developer</div>';
userName.textContent = 'john_developer';
document.querySelector('.user-avatar').textContent = '👨💻';
createConfetti();
}, 500);
}
// Simulate not logged in
function simulateNotLoggedIn() {
const terminal = document.getElementById('terminal');
const userName = document.getElementById('userName');
terminal.innerHTML = '<div class="terminal-line"><span class="terminal-prompt">$</span> npm whoami</div>';
setTimeout(() => {
terminal.innerHTML += '<div class="terminal-error" style="margin-top: 10px;">npm ERR! code ENEEDAUTH</div>';
terminal.innerHTML += '<div class="terminal-error">npm ERR! need auth This command requires you to be logged in.</div>';
terminal.innerHTML += '<div class="terminal-error">npm ERR! need auth You need to authorize this machine using `npm login`</div>';
userName.textContent = 'Not Logged In';
document.querySelector('.user-avatar').textContent = '❌';
}, 500);
}
// Simulate scoped
function simulateScoped() {
const terminal = document.getElementById('terminal');
const userName = document.getElementById('userName');
terminal.innerHTML = '<div class="terminal-line"><span class="terminal-prompt">$</span> npm whoami</div>';
setTimeout(() => {
terminal.innerHTML += '<div class="terminal-success" style="margin-top: 10px;">mycompany</div>';
terminal.innerHTML += '<div style="color: var(--accent-cyan); margin-top: 10px;">💼 Organization account</div>';
userName.textContent = 'mycompany';
document.querySelector('.user-avatar').textContent = '🏢';
createConfetti();
}, 500);
}
// 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 = ['#a855f7', '#3b82f6', '#10b981', '#ec4899', '#06b6d4'];
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