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.js

node -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.

node

node --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.js

Debugging

node --inspect <script> — Start with debugger listening (connect via Chrome DevTools).

node --inspect app.js

node --inspect-brk <script> — Start with debugger and break before first line.

node --inspect-brk app.js

node --inspect=<host>:<port> <script> — Debug on a custom host and port.

node --inspect=0.0.0.0:9229 server.js

node --prof <script> — Generate V8 CPU profiling output.

node --prof app.js

node --prof-process <isolate-file> — Process V8 profiling output into readable format.

node --prof-process isolate-0x*.log > profile.txt

Environment & Config

NODE_ENV=production node <script> — Run with a specific environment.

NODE_ENV=production node server.js

node --max-old-space-size=<MB> <script> — Set maximum heap memory size.

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

node --env-file=<file> <script> — Load environment variables from a file (Node 20.6+).

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

node -r <module> <script> — Preload/require a module before running the script.

node -r dotenv/config app.js

node --experimental-vm-modules <script> — Enable experimental VM modules support.

node --experimental-vm-modules test.js

ES Modules & TypeScript

node --loader ts-node/esm <script> — Run TypeScript files directly with ts-node.

node --loader ts-node/esm app.ts

node --experimental-strip-types <script> — Run TypeScript files natively (Node 22.6+).

node --experimental-strip-types app.ts

node --conditions <condition> <script> — Set custom package.json export conditions.

node --conditions development app.js

Info & Diagnostics

node --version — Show the installed Node.js version.

node --version

node -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 harmony

node --report-on-fatalerror <script> — Generate a diagnostic report on fatal errors.

node --report-on-fatalerror server.js

node --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

  • artisan – CLI of the Laravel PHP framework for migrations, tasks and code generation
  • cargo – package manager and build tool for the Rust programming language
  • composer – dependency management for PHP projects