process
process is an ambient global object, available in every module without an import — just like
console. It exposes synchronous access to the running process, backed by libc.
console.log("running in: " + process.cwd());process.setEnv("GREETING", "hi");console.log(process.getEnv("GREETING")); // "hi"Environment
process.getEnv(name: string): string // value, or "" if unsetprocess.hasEnv(name: string): boolean // distinguishes "set but empty" from "unset"process.setEnv(name: string, value: string): voidif (process.hasEnv("HOME")) { console.log(process.getEnv("HOME"));}Working directory
process.cwd(): string // current working directoryprocess.chdir(path: string): boolean // change directory; true on successCommand-line arguments & identity
process.argv(): string[] // [program path, ...user args]process.execPath(): string // absolute path of the running executableprocess.platform(): string // "darwin" | "linux"process.arch(): string // "arm64" | "x64"let args: string[] = process.argv();let i: i32 = 1; // argv[0] is the program pathwhile (i < args.length) { console.log("arg: " + args[i]); i = i + 1;}Process control
process.pid(): i32 // this process's idprocess.ppid(): i32 // parent process idprocess.hrtime(): i64 // high-resolution time in nanosecondsprocess.exit(code: i32): void // terminate immediately with an exit codeprocess.hrtime() is a monotonic nanosecond counter; measure elapsed time by subtracting two
readings.
if (!process.hasEnv("REQUIRED_TOKEN")) { console.error("REQUIRED_TOKEN is not set"); process.exit(1);}