# Run a JavaScript filenodeapp.js# Start the REPL (interactive shell)node# Check Node.js versionnode-v# Run with debuggingnode--inspectapp.js# Run with V8 inspector for Chrome DevToolsnode--inspect-brkapp.js
Advanced
# Run with specific memory allocationnode--max-old-space-size=4096app.js# Check for syntax errors without executingnode--checkapp.js# Show all deprecation warningsnode--trace-deprecationapp.js# Run with experimental featuresnode--experimental-modulesapp.js# Print environment variablesnode-p"process.env"# Run with native profilingnode--profapp.js
npm Commands
Package Installation
# Install all dependencies from package.jsonnpminstall# Install a specific package locallynpminstallpackage-name# Install a specific package globallynpminstall-gpackage-name# Install as a development dependencynpminstall--save-devpackage-name# Install exact version (no ^ or ~)npminstall--save-exactpackage-name# Install a specific versionnpminstallpackage-name@1.2.3
Package Management
# Uninstall a package locallynpmuninstallpackage-name# Uninstall a package globallynpmuninstall-gpackage-name# Update all packagesnpmupdate# Update a specific packagenpmupdatepackage-name# Check outdated packagesnpmoutdated# List installed packagesnpmlist# List top-level installed packagesnpmlist--depth=0# List global packagesnpmlist-g--depth=0
Project Management
# Initialize a new projectnpminit# Initialize with defaults (skips questions)npminit-y# Run a script defined in package.jsonnpmrunscript-name# Run the start scriptnpmstart# Run the test scriptnpmtest# Run the build scriptnpmrunbuild
Package Publishing
# Create a tarballnpmpack# Publish a package to npm registrynpmpublish# Tag a package with a specific tagnpmpublish--tagbeta# Increment patch version (1.0.0 → 1.0.1)npmversionpatch# Increment minor version (1.0.0 → 1.1.0)npmversionminor# Increment major version (1.0.0 → 2.0.0)npmversionmajor
npm Configuration
# Set npm config valuenpmconfigsetkeyvalue# Get npm config valuenpmconfiggetkey# List all config settingsnpmconfiglist# Edit config file with default editornpmconfigedit# Set init defaultsnpmconfigsetinit.author.name"Your Name"npmconfigsetinit.author.email"your.email@example.com"
Dependency Analysis
# View dependency treenpmls# Check for security vulnerabilitiesnpmaudit# Fix security vulnerabilities automaticallynpmauditfix# Get info about a packagenpminfopackage-name# View package.json of a dependencynpmviewpackage-name
nvm Commands
Installation & Version Management
# List available Node.js versionsnvmls-remote# Install latest LTS Node.js versionnvminstall--lts# Install specific Node.js versionnvminstall16.14.0# Use a specific Node.js versionnvmuse16.14.0# Set default Node.js versionnvmaliasdefault16.14.0# List installed versionsnvmls# Run a command with a specific versionnvmexec14.17.0nodeapp.js
Project Management
# Use .nvmrc file in current directorynvmuse# Create .nvmrc file with current versionnode-v>.nvmrc# Install version from .nvmrcnvminstall
System Management
# Show current Node.js versionnvmcurrent# Show path to executablenvmwhich16.14.0# Uninstall a versionnvmuninstall14.17.0# Show nvm versionnvm--version# Clear nvm cachenvmcacheclear
Advanced nvm Usage
# Install with custom arch (32-bit)nvminstall--arch=x8614.17.0# Use with specific environment variablesnvmuse--silent16.14.0# Run Node.js with specific flagsnvmrun16.14.0--max-old-space-size=4096app.js# Install version for specific projectcdproject-directory&&nvminstall
Combined Workflows
Project Setup
# Set up a new project with specific Node.js versionnvminstall16.14.0nvmuse16.14.0npminit-ynpminstallexpressmongoosedotenv
Development Workflow
# Start development server with automatic restartnpminstall--save-devnodemon# Add to package.json: "dev": "nodemon app.js"npmrundev
Production Deployment
# Install only production dependenciesnpminstall--production# Run in production modeNODE_ENV=productionnodeapp.js
Performance Testing
# Run with heap snapshotnode--heapsnapshot-signal=SIGUSR2app.js# Run with CPU profilingnode--profapp.js# After running, analyze with:node--prof-processisolate-*.log>profile.txt
Package Maintenance
# Update npm itselfnpminstall-gnpm@latest# Update all dependencies to latest versionsnpxnpm-check-updates-unpminstall