Skip to main content

Os

The handful of operating-system facts worth a named helper — platform, architecture, release, home and temp directories. Each one guards on process being present and returns undefined off Node rather than throwing, so a shared module can call them without a runtime check. They are passthroughs, so you get exactly what Node reports ('darwin', not 'macOS'); for browser-side platform sniffing use system.

Example

import { getHomeDir, getOsPlatform, getTmpDir } from '@rtorcato/js-common/os'

// Off Node these return `undefined` instead of throwing, so a module shared with
// the browser can call them without a runtime guard.
const cacheDir = `${getHomeDir() ?? getTmpDir()}/.myapp`

getOsPlatform() // 'darwin' | 'linux' | 'win32' — Node's own strings, unmapped

Import

import { getHomeDir, getOsArch, getOsPlatform } from '@rtorcato/js-common/os'

Exports

NameSummary
getHomeDirReturns the user's home directory (Node.js only).
getOsArchReturns the OS architecture (Node.js only).
getOsPlatformReturns the current operating system platform (Node.js only).
getOsReleaseReturns the OS release/version (Node.js only).
getTmpDirReturns the system's temporary directory (Node.js only).

See also

  • node — Node version checks and optional requires
  • process — cwd, pid, uptime, exit, CI detection
  • system — detect OS, mobile platform and touch support
  • env — read env vars and branch on NODE_ENV