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

Source: https://www.jpkc.com/db/en/cheatsheets/build-languages/node/

<!-- PROSE:intro -->
`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.
<!-- PROSE:intro:end -->

## Run Scripts

`node <script>` — Execute a JavaScript file.

```bash
node app.js
```

`node -e '<code>'` — Execute JavaScript from the command line.

```bash
node -e 'console.log(Math.random())'
```

`node -p '<expression>'` — Evaluate and print the result of an expression.

```bash
node -p 'process.versions.v8'
```

`node --input-type=module -e '<code>'` — Run ES module code from command line.

```bash
node --input-type=module -e 'import {readFile} from "fs/promises"; console.log("ok")'
```

`node - < <script>` — Read and execute script from stdin.

```bash
echo 'console.log(42)' | node -
```

## REPL & Interactive

`node` — Start the interactive REPL.

```bash
node
```

`node --experimental-repl-await` — Start REPL with top-level await support.

```bash
node --experimental-repl-await
```

`.help` — Show REPL commands (inside REPL).

```bash
.help
```

`.load <file>` — Load a file into the REPL session.

```bash
.load utils.js
```

`.save <file>` — Save REPL session to a file.

```bash
.save session.js
```

## Debugging

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

```bash
node --inspect app.js
```

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

```bash
node --inspect-brk app.js
```

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

```bash
node --inspect=0.0.0.0:9229 server.js
```

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

```bash
node --prof app.js
```

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

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

## Environment & Config

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

```bash
NODE_ENV=production node server.js
```

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

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

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

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

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

```bash
node -r dotenv/config app.js
```

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

```bash
node --experimental-vm-modules test.js
```

## ES Modules & TypeScript

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

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

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

```bash
node --experimental-strip-types app.ts
```

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

```bash
node --conditions development app.js
```

## Info & Diagnostics

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

```bash
node --version
```

`node -p 'process.versions'` — Show all runtime component versions (V8, OpenSSL, etc.).

```bash
node -p 'process.versions'
```

`node -p 'process.arch'` — Show the CPU architecture.

```bash
node -p 'process.arch'
```

`node --v8-options | grep <flag>` — Search V8 engine flags.

```bash
node --v8-options | grep harmony
```

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

```bash
node --report-on-fatalerror server.js
```

`node --heap-prof <script>` — Generate heap profiling data.

```bash
node --heap-prof app.js
```

<!-- PROSE:outro -->
## 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](https://nodejs.org/docs/latest/api/) – official API reference for every built-in module
- [Learn Node.js](https://nodejs.org/en/learn) – official guides and tutorials
- [Command-line options](https://nodejs.org/api/cli.html) – complete reference for every CLI flag and environment variable
<!-- PROSE:outro:end -->

## Related Commands

- [artisan](https://www.jpkc.com/db/en/cheatsheets/build-languages/artisan/) – CLI of the Laravel PHP framework for migrations, tasks and code generation
- [cargo](https://www.jpkc.com/db/en/cheatsheets/build-languages/cargo/) – package manager and build tool for the Rust programming language
- [composer](https://www.jpkc.com/db/en/cheatsheets/build-languages/composer/) – dependency management for PHP projects

