Skip to main content
process is a small global for inspecting and controlling the running program: arguments, environment, working directory, identity, and exit. Subprocesses live on the separate child_process global.

Quick look

Reference

Permissions: process.env needs --allow-env; process.chdir needs --allow-read on the target; process.kill to a PID other than process.pid needs --allow-run=kill. Everything else in this table is ungated. See Permissions.

Arguments: argv

argv[0] is the runtime, argv[1] is your script — user args start at index 2:
Permission flags are not stripped from argv: ff app.js --allow-read=. leaves --allow-read=. in process.argv. They are also interpreted as policy, so do not use a --allow-*-shaped value as an application argument. A tiny flag parser needs nothing else:

Environment: env

A plain object with string values, built at startup from the OS environment and filtered by --allow-env. A name outside the grant is absent, so it reads as undefined — fail fast on required ones:
process.env is a startup snapshot and there is no .env loader. Export variables (or prefix the command, as above) before starting ff. Only granted names are copied into the object; bare --allow-env grants all of them. The FF_* variables (FF_ECHO, FF_CERT, FF_KEY, FF_CA_FILE) are read by the runtime itself, but the application sees them only if --allow-env includes them. See the env guide.

Working directory: cwd / chdir

chdir throws PermissionDenied when the target is outside the read scopes. Once allowed, a missing or unreachable path is a silent no-op and the cwd stays put. Check process.cwd() afterwards when the directory is user-supplied.
Scope roots are fixed at launch. A later chdir does not move them, so --allow-read=. remains the launch directory. Relative fs paths resolve against the new cwd and must still land inside a scope captured at startup. Relative file paths in fs and module-adjacent lookups resolve against the cwd, so chdir before serving from a data dir is a legitimate pattern. Prefer absolute paths in long-lived servers to avoid surprises.

Exiting: exit

  • Codes clamp to 0–255 (exit(300) → 255, exit(-5) → 0) — clamped, not wrapped mod 256.
  • exit() stops the event loop immediately — pending timers, connections, and workers do not drain. The test helper done() relies on this to end server-fixture tests cleanly.
  • Non-zero codes fail CI (make test, test/run.sh treat them as failure).
  • An uncaught throw — at the top level of your script or of an imported module — prints Error: … with its stack to stderr and exits 1 on its own; no catch-all needed.
Graceful shutdown: use process.on("SIGTERM", ...) / process.once("SIGINT", ...) together with await server.close() to drain active HTTP connections before exiting. When http.serve is running and no custom listener is registered for SIGINT or SIGTERM, the runtime drains the server automatically on those signals.

Practical example: CLI with subcommands

greet is pure JS and needs no flags. serve needs net, plus env if it should read PORT.

What process does not have

(process.memoryUsage() does exist — its rss is a peak counter from getrusage, see the API page.) Need Postgres? Use the built-in SQL client — no driver to install.

Troubleshooting

process.env.X is undefined — either the variable wasn’t exported in the launching shell, or --allow-env does not include it. Check both: X=1 ff app.js --allow-env=X. No .env file is read. chdir threw PermissionDenied — the target is outside every read scope. Add --allow-read=<target> (or a parent directory). This is different from a missing directory, which is still a silent no-op. chdir didn’t move me — the path is allowed but missing or unreachable. It returns undefined and leaves the cwd unchanged; log process.cwd() after the call to confirm. Exit code surprises — codes clamp to 0–255 and exit() skips all draining. For “finish work then quit”, drain first, then exit. An uncaught top-level or module throw already exits 1 by itself; errors thrown inside an HTTP handler become a 500 response instead. process.spawn is not a function — subprocesses live on the separate child_process global: child_process.exec("…") or child_process.spawn(cmd, args).