process is a small global for inspecting and controlling the running program: arguments, environment, working directory, identity, signals, and exit. Subprocesses live on the separate child_process global.
Quick look
Reference
Permissions
Only three members are gated:
Everything else —
argv, cwd, exit, pid, platform, arch,
on, once, off, removeListener, memoryUsage, stats — is always
available. process.exit() works even when every category is denied.
Arguments: argv
argv[0] is the runtime, argv[1] is your script — user args start at index 2:
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, not a live view, 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.Working directory: cwd / chdir
chdir has two distinct failure modes:
- Permission denial — the target is outside the
readscopes. It throws anErrornamedPermissionDeniedwithcode: "PERMISSION_DENIED"before the working directory changes. - OS failure — the path was allowed but is missing or unreachable. It
returns
undefinedand the cwd stays put. Verify withprocess.cwd()when the path is user-supplied.
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
- Code is clamped to 0–255 (
exit(300)→ 255,exit(-5)→ 0,exit()→ 0). exit()stops the event loop immediately — pending timers, connections, and workers do not drain. The test helperdone()relies on this to end server-fixture tests cleanly.- Non-zero codes fail CI (
make test,test/run.shtreat 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 exits1on its own; no catch-all needed.
Signals and graceful shutdown: on, once, off, kill
Listen for POSIX signals (SIGINT, SIGTERM, SIGHUP, SIGUSR1, SIGUSR2)
to drain servers or clean up resources before exiting:
- Up to 8 listeners can be attached per signal.
- Signal handlers run asynchronously on the event loop tick after the OS signal arrives.
- When
http.serveis running and no user listener is registered forSIGINT/SIGTERM, the runtime automatically triggersserver.close()on those signals. process.kill(pid, signal?)sends a signal ("SIGTERM"when omitted). Signalingprocess.pidneeds no permission flag; signaling another process requires--allow-run=kill(or bare--allow-run).
Memory and allocator introspection
process.memoryUsage()
Returns an object with the current process Resident Set Size (rss) in bytes:
process.stats()
Returns internal runtime counters tracking heap spills, buffer reuse, and pool activity grouped by subsystem (fetch, http, pg, child):
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 silently does nothing — the path is allowed but missing or
unreachable. It returns undefined and leaves the cwd unchanged; call
process.cwd() afterwards when the dir is user-supplied.
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).