Runtime agnostic JavaScript utility library for environment detection, platform information, CI/CD provider detection, and runtime identification.
—
Cross-platform environment variable access that works consistently across Node.js, Deno, Bun, and browser environments using a Proxy-based approach.
The env proxy provides universal access to environment variables across different JavaScript runtimes.
/**
* Cross-platform environment variable proxy that works across all JavaScript runtimes
* Supports Node.js process.env, Deno.env, import.meta.env, and browser globalThis.__env__
*/
const env: EnvObject;
type EnvObject = Record<string, string | undefined>;Usage Examples:
import { env } from "std-env";
// Read environment variables
const apiKey = env.API_KEY;
const nodeEnv = env.NODE_ENV;
const port = env.PORT || "3000";
// Set environment variables (when possible)
env.DEBUG = "true";
// Check if environment variable exists
if ("DATABASE_URL" in env) {
console.log("Database URL is configured");
}
// Iterate over environment variables
for (const key of Object.getOwnPropertyNames(env)) {
console.log(`${key}: ${env[key]}`);
}The env proxy automatically detects the runtime and uses the appropriate environment access method:
process.envDeno.env.toObject()import.meta.envglobalThis.__env__Direct access to the NODE_ENV environment variable with fallback to empty string.
/**
* Value of NODE_ENV environment variable or empty string if not set
* Specifically reads from process.env.NODE_ENV when available
*/
const nodeENV: string;Usage Examples:
import { nodeENV } from "std-env";
// Check specific Node.js environment
if (nodeENV === "production") {
console.log("Running in production mode");
} else if (nodeENV === "development") {
console.log("Running in development mode");
} else if (nodeENV === "test") {
console.log("Running in test mode");
}
// Use as fallback when env proxy might not be available
const environment = nodeENV || "development";The environment variable system works across all supported JavaScript runtimes:
process.env directlyDeno.env.toObject() for read accessprocess.envimport.meta.env (Vite/bundlers) or globalThis.__env__Install with Tessl CLI
npx tessl i tessl/npm-std-env