@vyriy/env
Part of Vyriy - a calm architecture toolkit for TypeScript, React, SSR, SSG, APIs, and cloud-ready apps.
Shared environment variable helpers for Vyriy projects.
Purpose
This package provides small helpers for reading common environment variables used across local development, AWS, ECS, GitLab CI, LocalStack, logging, and stage detection.
Install
With npm:
npm install @vyriy/env
With Yarn:
yarn add @vyriy/env
Usage
import { existsEnv, getEnv, getNodeEnv, getStage, isProduction } from '@vyriy/env';
const appName = getEnv('APP_NAME');
const nodeEnv = getNodeEnv();
const stage = getStage();
const hasOptionalFeature = existsEnv('OPTIONAL_FEATURE');
if (isProduction() && hasOptionalFeature) {
console.log({ appName, nodeEnv, stage });
}
API
Core:
existsEnv(name)getEnv(name, defaultValue?)getNodeEnv()isNodeEnvProduction()isNodeEnvDevelopment()isNodeEnvTest()
AWS / CDK / ECS:
getRegion()getAwsRegion()getAwsDefaultRegion()getAccessKeyId()getSecretAccessKey()getCdkAccount()getCdkRegion()getStack()getEcsClusterName()getEcsTaskDefinition()getEcsContainerName()getTask()
CI / local tooling:
getCiPipelineId()getCiMergeRequestId()getCiProjectName()getLocalstackHost()getLocalstackPort()getLogLevel()
Server:
getPort()
Stage helpers:
getStage()isLocal()isDev()isDevelop()isTest()isTesting()isQa()isUat()isStaging()isPreProd()isPreProduction()isFeature()isHotfix()isProduction()
Notes
existsEnvonly checks whether the variable is defined.getEnvthrows if the variable is missing and no default value is provided.- Stage helpers are based on the
STAGEenvironment variable. getNodeEnvdefaults to'development'.