node — The Node.js Runtime on the Command Line
The Node.js runtime on the command line — run scripts, start a REPL, debug apps, set flags and manage your JavaScript environment.
node is the command-line entry point to Node.js, the server-side JavaScript runtime built on Google's V8 engine. With it you run script files, evaluate snippets inline, open an interactive REPL, attach a debugger and tune the runtime through dozens of flags and environment variables. This guide collects the commands you reach for daily — from a quick node -e one-liner to heap profiling and native TypeScript support.
Run Scripts
node <script> — Execute a JavaScript file.
node app.jsnode -e '<code>' — Execute JavaScript from the command line.
node -e 'console.log(Math.random())'node -p '<expression>' — Evaluate and print the result of an expression.
node -p 'process.versions.v8'node --input-type=module -e '<code>' — Run ES module code from command line.
node --input-type=module -e 'import {readFile} from "fs/promises"; console.log("ok")'node - < <script> — Read and execute script from stdin.
echo 'console.log(42)' | node -REPL & Interactive
node — Start the interactive REPL.
nodenode --experimental-repl-await — Start REPL with top-level await support.
node --experimental-repl-await.help — Show REPL commands (inside REPL).
.help.load <file> — Load a file into the REPL session.
.load utils.js.save <file> — Save REPL session to a file.
.save session.jsDebugging
node --inspect <script> — Start with debugger listening (connect via Chrome DevTools).
node --inspect app.jsnode --inspect-brk <script> — Start with debugger and break before first line.
node --inspect-brk app.jsnode --inspect=<host>:<port> <script> — Debug on a custom host and port.
node --inspect=0.0.0.0:9229 server.jsnode --prof <script> — Generate V8 CPU profiling output.
node --prof app.jsnode --prof-process <isolate-file> — Process V8 profiling output into readable format.
node --prof-process isolate-0x*.log > profile.txtEnvironment & Config
NODE_ENV=production node <script> — Run with a specific environment.
NODE_ENV=production node server.jsnode --max-old-space-size=<MB> <script> — Set maximum heap memory size.
node --max-old-space-size=4096 build.jsnode --env-file=<file> <script> — Load environment variables from a file (Node 20.6+).
node --env-file=.env app.jsnode -r <module> <script> — Preload/require a module before running the script.
node -r dotenv/config app.jsnode --experimental-vm-modules <script> — Enable experimental VM modules support.
node --experimental-vm-modules test.jsES Modules & TypeScript
node --loader ts-node/esm <script> — Run TypeScript files directly with ts-node.
node --loader ts-node/esm app.tsnode --experimental-strip-types <script> — Run TypeScript files natively (Node 22.6+).
node --experimental-strip-types app.tsnode --conditions <condition> <script> — Set custom package.json export conditions.
node --conditions development app.jsInfo & Diagnostics
node --version — Show the installed Node.js version.
node --versionnode -p 'process.versions' — Show all runtime component versions (V8, OpenSSL, etc.).
node -p 'process.versions'node -p 'process.arch' — Show the CPU architecture.
node -p 'process.arch'node --v8-options | grep <flag> — Search V8 engine flags.
node --v8-options | grep harmonynode --report-on-fatalerror <script> — Generate a diagnostic report on fatal errors.
node --report-on-fatalerror server.jsnode --heap-prof <script> — Generate heap profiling data.
node --heap-prof app.js Conclusion
The node binary is far more than a script launcher: the right flags turn it into a debugger, profiler, memory tuner or even a TypeScript runner. Reach for --inspect when something misbehaves, --env-file to keep secrets out of your code, and node -p for quick introspection of the runtime. Treat experimental flags (--experimental-*) with care — they can change or disappear between releases, so avoid them in production. NODE_OPTIONS is convenient but applies to every Node process in the shell, and remember that running an unfamiliar script executes its code with your full privileges — read before you run.
Further Reading
- Node.js Documentation – official API reference for every built-in module
- Learn Node.js – official guides and tutorials
- Command-line options – complete reference for every CLI flag and environment variable