Core concepts
Runtime adapter
A common API for the runtime name, version, environment, arguments, and current directory.
Runtime adapter
Create an adapter
import { createRuntimeAdapter } from 'oruntime'
const runtime = createRuntimeAdapter()
interface RuntimeAdapter {
readonly name: Runtime
readonly version: string | undefined
readonly capabilities: Readonly<RuntimeCapabilities>
getEnv(): Record<string, string>
getEnv(key: string): string | undefined
cwd(): string | undefined
argv(): string[]
}
Name and version
| Runtime | Version source |
|---|---|
| Node.js | process.versions.node |
| Bun | Bun.version |
| Deno | Deno.version.deno |
| workerd | Not guaranteed |
| Browser | Not guaranteed |
undefined means that no reliable version is exposed. User-agent text is intentionally not parsed as a guaranteed version.
Environment variables
Read one value:
const apiURL = runtime.getEnv('API_URL')
Read a copy of every accessible value:
const environment = runtime.getEnv()
environment.NODE_ENV = 'test' // Does not modify the native environment.
In Deno, missing permission throws PermissionDeniedError; it is not treated as a missing variable.
Current directory
const directory = runtime.cwd()
Node.js, Bun, and Deno return their current directory. Environments without a process model return undefined.
User arguments
const args = runtime.argv()
Node.js and Bun use process.argv.slice(2); Deno copies Deno.args. A new array is always returned.
Strict mode
const runtime = createRuntimeAdapter({ throwOnUnknown: true })
This prevents creation of a neutral adapter for an unknown runtime. Use the adapter for runtime-specific information; import Fetch, URL, and timer utilities directly.