Process
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
Arguments: argv
argv[0] is the runtime, argv[1] is your script — user args start at index 2:
A tiny flag parser needs nothing else:
Environment: env
Plain object, string values only. Missing keys read as undefined — fail fast on required ones:
Note:
process.envis a startup snapshot and there is no.envloader. Export variables (or prefix the command, as above) before startingff. TheFF_variables (FF_ECHO,FF_CERT,FF_KEY,FF_CA_FILE) are read the same way — see the env guide.
Working directory: cwd / chdir
chdir never throws: on a missing/unreachable path it returns undefined and the cwd stays put. Verify with process.cwd() if the path is user-supplied.
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.
Note: There is no signal-handling API. Stop servers with
Ctrl-Cfrom the terminal, orprocess.exit(0)for programmatic shutdown.
Practical example: CLI with subcommands
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 — the variable wasn't exported in the launching shell. X=1 ff app.js (prefix) or export X=1 first. No .env file is read.
chdir silently does nothing — the path is missing or unreachable. It never throws; 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).
