envFn (src/env-helper.ts)

strapi · packages/core/utils/src/env-helper.ts · typescript · MIT
infra, tag:knn-classified

Typed helper for accessing environment variables with type safety and parsing utilities.

// Source: https://github.com/strapi/strapi | License: MIT | Copyright 2015-present Strapi Solutions SAS
// Provided via justclaw.it.com; keep this notice with the code.
import _ from 'lodash';

export type Env = typeof envFn & typeof utils;

function envFn(key: string): string | undefined;
function envFn(key: string, defaultValue: string): string;
function envFn<T>(key: string, defaultValue: T): (string & Record<never, never>) | T;
function envFn(key: string, defaultValue?: any): any {
  return _.has(process.env, key) ? process.env[key] : defaultValue;
}

function getKey(key: string) {
  return process.env[key] ?? '';
}

function int(key: string, defaultValue: number): number;
function int(key: string, defaultValue?: number | undefined): number | undefined;
function int(key: string, defau

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key