typestar

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

  1. argv[0] is node and argv[1] the script; yours start at 2.
  2. process.env values are always strings or undefined.
  3. Set exitCode rather than calling exit, so buffers flush.

Keywords and builtins used here

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.

Type this snippet

Step 1 of 3 in The process, step 7 of 18 in Node.js.

← Previous Next →