CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-std-env

Runtime agnostic JavaScript utility library for environment detection, platform information, CI/CD provider detection, and runtime identification.

Pending
Overview
Eval results
Files

environment-variables.mddocs/

Environment Variables

Cross-platform environment variable access that works consistently across Node.js, Deno, Bun, and browser environments using a Proxy-based approach.

Capabilities

Environment Variable Proxy

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:

  • Node.js: process.env
  • Deno: Deno.env.toObject()
  • Vite/Rollup: import.meta.env
  • Browser/Custom: globalThis.__env__

Node.js Environment Variable

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";

Runtime Compatibility

The environment variable system works across all supported JavaScript runtimes:

  • Node.js: Uses process.env directly
  • Deno: Uses Deno.env.toObject() for read access
  • Bun: Compatible with Node.js process.env
  • Browser: Uses import.meta.env (Vite/bundlers) or globalThis.__env__
  • Edge Runtimes: Falls back to available global environment objects

Install with Tessl CLI

npx tessl i tessl/npm-std-env

docs

environment-detection.md

environment-variables.md

index.md

platform-detection.md

provider-detection.md

runtime-detection.md

tile.json