Configuration

All configuration options for @redenv/client.

The Redenv constructor accepts a configuration object. Here's a complete example:

lib/redenv.ts
import {  } from "@redenv/client";

export const  = new ({
  // Required
  : "my-app",
  : "stk_yYt2HXRprwYgpvwv",
  : "redenv_sk_8f3a9b2c...",
  : {
    : "https://your-redis.upstash.io",
    : "AXxxxxxxxxxxxxxxx",
  },

  // Optional
  : "production",
  : { : 300, : 86400 },
  : { : true },
  : "low",
});

All Options#

OptionTypeRequiredDefaultDescription
projectstringYesYour Redenv project name
tokenIdstringYesService Token public ID (stk_...)
tokenstringYesService Token secret key (redenv_sk_...)
upstash.urlstringYesUpstash Redis REST URL
upstash.tokenstringYesUpstash Redis REST Token
environmentstringNo"development"Environment to fetch secrets from
cache.ttlnumberNo300Seconds before data is stale
cache.swrnumberNo86400Seconds stale data can be served while refreshing
env.overridebooleanNotrueOverwrite existing process.env variables
log"none" | "low" | "high"No"low"Logging verbosity

Warning

Never hardcode credentials. Load them from environment variables. These "bootstrap" secrets are the only ones you manage outside Redenv.

Option Details#

environment#

ValueDescription
"development"Default. Local development
"staging"Pre-production testing
"production"Live production secrets
Any custom stringYour own environment names
environment: process.env.NODE_ENV || "development";

cache#

Uses stale-while-revalidate strategy. Preset configurations:

Use CaseTTLSWRExample
Default30086400General purpose
High-frequency updates1060Feature flags, A/B tests
Stable secrets360086400API keys, database URLs
Serverless30300Vercel, Lambda (ephemeral instances)
Development530See changes quickly

Info

For a deep dive into how caching works, scale impact, and architecture, see Caching Strategy.

env.override#

When false, existing process.env variables are preserved. Useful for local .env overrides during development.

log#

ValueDescription
"none"No logs
"low"Errors and important info only
"high"Verbose logging (cache hits/misses, refreshes)

Example output with "high":

[REDENV] Cache HIT (fresh): redenv:my-app:production
[REDENV] Cache HIT (stale): redenv:my-app:production - triggering background refresh
[REDENV] Cache MISS: redenv:my-app:staging - fetching from Redis

TypeScript Interface#

interface RedenvOptions {
  // Required
  project: string;
  tokenId: string;
  token: string;
  upstash: {
    url: string;
    token: string;
  };

  // Optional
  environment?: string;
  cache?: {
    ttl?: number;
    swr?: number;
  };
  env?: {
    override?: boolean;
  };
  log?: "none" | "low" | "high";
}

Best Practice: Singleton Pattern#

Create a single Redenv instance and export it. This ensures cache is shared across your app:

lib/redenv.ts
import { Redenv } from "@redenv/client";

export const redenv = new Redenv({
  project: process.env.REDENV_PROJECT!,
  tokenId: process.env.REDENV_TOKEN_ID!,
  token: process.env.REDENV_TOKEN_KEY!,
  upstash: {
    url: process.env.UPSTASH_REDIS_URL!,
    token: process.env.UPSTASH_REDIS_TOKEN!,
  },
  environment: process.env.NODE_ENV || "development",
});

// pre-fetches secrets into process.env at startup
await redenv.init(); 
anywhere else
import { redenv } from "@/lib/redenv";

const secrets = await redenv.load();