The process object in JavaScript
Arguments, environment, exit codes and the current directory.
console.log(process.argv.length >= 2, typeof process.argv[1]);
console.log(process.env.TYPESTAR_THEME ?? "default");
console.log(typeof process.cwd(), process.platform.length > 0);
console.log(process.version.startsWith("v"), process.pid > 0);
const before = process.memoryUsage().heapUsed;
const held = new Array(10_000).fill("x");
console.log(process.memoryUsage().heapUsed > before, held.length);
process.on("exit", (code) => console.log("exiting with", code));
process.exitCode = 0;
How it works
argv[0]is node andargv[1]the script; yours start at 2.process.envvalues are always strings or undefined.- Set
exitCoderather than callingexit, so buffers flush.
Keywords and builtins used here
Arrayconst
The run, in numbers
- Lines
- 11
- Characters to type
- 488
- Tokens
- 145
- Three-star pace
- 105 tpm
At the three-star pace of 105 tokens a minute, this run takes about 83 seconds.
Step 1 of 3 in The process, step 7 of 18 in Node.js.