← Back to Home

Node.js Cheat Sheet

Essential Node.js runtime commands and flags

node
Execute a JavaScript file with Node.js runtime. Basic command to run Node.js applications.

node app.js

Keywords: execute, run, javascript, file, runtime

node -v
Display the current Node.js version. Useful for checking installed version.

node -v

Keywords: version, check, current, installed

node --version
Display the current Node.js version. Alternative to -v flag.

node --version

Keywords: version, check, current, installed

node -e
Execute JavaScript code directly from command line. Useful for quick scripts and testing.

node -e "console.log('Hello World')"

Keywords: execute, inline, code, script, quick

node -p
Execute and print result of JavaScript expression. Combines -e with automatic console.log.

node -p "Math.PI * 2"

Keywords: print, execute, expression, result, math

node --inspect
Start Node.js with debugging enabled. Opens debugger on default port 9229.

node --inspect app.js

Keywords: debug, inspect, debugger, port, development

node --inspect-brk
Start Node.js with debugging and break on first line. Useful for debugging startup issues.

node --inspect-brk app.js

Keywords: debug, inspect, break, first, line, startup

node --watch
Watch for file changes and restart automatically. Built-in file watching (Node.js 18+).

node --watch app.js

Keywords: watch, restart, automatic, changes, development

node --env-file
Load environment variables from a file. Built-in .env file support (Node.js 20+).

node --env-file=.env app.js

Keywords: environment, variables, env, file, config

node --max-old-space-size
Set maximum memory for V8 heap. Increase memory limit for large applications.

node --max-old-space-size=4096 app.js

Keywords: memory, heap, limit, v8, performance

node --trace-warnings
Show stack traces for process warnings. Helpful for debugging deprecation warnings.

node --trace-warnings app.js

Keywords: trace, warnings, stack, debug, deprecation

node --experimental-modules
Enable experimental ES modules support. For using import/export syntax.

node --experimental-modules app.mjs

Keywords: experimental, modules, es6, import, export

node --loader
Specify custom module loader. For transforming modules during import.

node --loader ./my-loader.js app.js

Keywords: loader, custom, module, transform, import

node --cpu-prof
Generate CPU profile for performance analysis. Creates .cpuprofile file.

node --cpu-prof app.js

Keywords: cpu, profile, performance, analysis, profiling

node --heap-prof
Generate heap profile for memory analysis. Creates .heapprofile file.

node --heap-prof app.js

Keywords: heap, profile, memory, analysis, profiling

node --check
Check JavaScript syntax without executing. Useful for syntax validation.

node --check app.js

Keywords: check, syntax, validate, parse, lint

node --print
Execute script and print result. Similar to -p but for files.

node --print script.js

Keywords: print, execute, result, output, file

node --require
Preload module before executing main script. Useful for setup or polyfills.

node --require ./setup.js app.js

Keywords: require, preload, module, setup, polyfill

node --title
Set process title shown in process list. Useful for process identification.

node --title="My App" app.js

Keywords: title, process, name, identification, ps

node --zero-fill-buffers
Zero-fill new Buffer instances for security. Prevents memory leaks in buffers.

node --zero-fill-buffers app.js

Keywords: zero, fill, buffer, security, memory