Skip to main content

Process

Process-scoped facts and actions — cwd, pid, platform, uptime, exit and CI detection. Every helper reads process at call time rather than at import, so tests can change the environment without module-cache tricks, and each returns undefined off Node instead of throwing. isCI checks the conventional variables (CI, CONTINUOUS_INTEGRATION, BUILD_NUMBER, RUN_ID) that providers set.

Example

import { getCwd, isCI } from '@rtorcato/js-common/process'

// Skip the interactive prompt when nobody is there to answer it.
const overwrite = isCI() ? true : await confirm('overwrite dist/?')

getCwd() // read at call time, so a test can chdir without module-cache tricks

isCI checks the conventional variables — CI, CONTINUOUS_INTEGRATION, BUILD_NUMBER, RUN_ID — that GitHub Actions, GitLab CI and friends all set.

Import

import { exitProcess, getCwd, getProcessId } from '@rtorcato/js-common/process'

Exports

NameSummary
exitProcessExits the process with the given code (Node.js only).
getCwdReturns the current working directory (Node.js only).
getProcessIdReturns the current process ID (Node.js only).
getProcessPlatformReturns the current process platform (Node.js only).
getProcessUptimeReturns the current process uptime in seconds (Node.js only).
isCIReturns true if the process is running in a CI environment (Node.js only).

See also

  • node — Node version checks and optional requires
  • os — platform, arch, home and temp directories
  • env — read env vars and branch on NODE_ENV
  • console — clear or silence console output