npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

flixburst-environment_variables

v1.0.8

Published

A flexible and extensible package for environment variables

Downloads

38

Readme

flixburst-environment_variables

A robust, type-safe, and flexible environment variable management package for TypeScript applications. Provides comprehensive support for different environment sources, caching, and validation.

Features

  • 🔒 Type-safe environment variable management
  • 🔄 Multi-source support (process.env, import.meta.env)
  • 🚀 Performance optimized with memoization
  • 🛡️ Strict validation
  • 🔍 Source tracking
  • 📦 Framework-agnostic
  • 🔄 Singleton pattern

Installation

# Using npm
npm install flixburst-environment-variables

# Using yarn
yarn add flixburst-environment-variables

# Using pnpm
pnpm add flixburst-environment-variables

Framework Examples

Node.js

// server.ts
import { Environment, ensureRequiredEnvironmentVariables } from 'flixburst-environment-variables';

// Using the Environment class
const env = Environment.getInstance({
    location: 'server',
    requiredVariables: ['PORT', 'DATABASE_URL', 'NODE_ENV'],
});

const port = env.getVariable('PORT');
const dbUrl = env.getVariable('DATABASE_URL');
const nodeEnv = env.getVariable('NODE_ENV');

// Using the utility function
const { PORT, DATABASE_URL, NODE_ENV } = ensureRequiredEnvironmentVariables({
    location: 'server',
    requiredVariables: ['PORT', 'DATABASE_URL', 'NODE_ENV'],
});

// Create server
const server = createServer((req, res) => {
    // Use environment variables
    if (NODE_ENV === 'development') {
        console.log('Development mode');
    }

    // ... server logic
});

server.listen(PORT, () => {
    console.log(`Server running on port ${PORT}`);
    console.log(`Database URL: ${DATABASE_URL}`);
});

React

// App.tsx
import { Environment, ensureRequiredEnvironmentVariables } from 'flixburst-environment-variables';

// Using the Environment class
function App() {
    const config = {
        location: 'App',
        requiredVariables: ['REACT_APP_API_URL'],
    };

    const env = Environment.getInstance(config);
    const apiUrl = env.getVariable('REACT_APP_API_URL');

    return <div>API URL: {apiUrl}</div>;
}

// Using the utility function
function AppWithUtility() {
    const { REACT_APP_API_URL } = ensureRequiredEnvironmentVariables({
        location: 'App',
        requiredVariables: ['REACT_APP_API_URL'],
    });

    return <div>API URL: {REACT_APP_API_URL}</div>;
}

Vue 3

<script setup>
import { Environment, ensureRequiredEnvironmentVariables } from 'flixburst-environment-variables';

// Using the Environment class
const config = {
    location: 'App',
    requiredVariables: ['VITE_API_URL'],
};

const env = Environment.getInstance(config);
const apiUrl = env.getVariable('VITE_API_URL');

// Using the utility function
const { VITE_API_URL } = ensureRequiredEnvironmentVariables({
    location: 'App',
    requiredVariables: ['VITE_API_URL'],
});
</script>

<template>
    <div>API URL: {{ VITE_API_URL }}</div>
</template>

Angular

import { Component } from '@angular/core';
import { Environment, ensureRequiredEnvironmentVariables } from 'flixburst-environment-variables';

@Component({
    selector: 'app-root',
    template: ` <div>API URL: {{ apiUrl }}</div> `,
})
export class AppComponent {
    // Using the Environment class
    private env = Environment.getInstance({
        location: 'AppComponent',
        requiredVariables: ['API_URL'],
    });

    apiUrl = this.env.getVariable('API_URL');

    // Using the utility function
    private envVars = ensureRequiredEnvironmentVariables({
        location: 'AppComponent',
        requiredVariables: ['API_URL'],
    });

    constructor() {
        console.log('API URL from utility:', this.envVars.API_URL);
    }
}

SolidJS

import { Environment, ensureRequiredEnvironmentVariables } from 'flixburst-environment-variables';

// Using the Environment class
function App() {
    const config = {
        location: 'App',
        requiredVariables: ['VITE_API_URL'],
    };

    const env = Environment.getInstance(config);
    const apiUrl = env.getVariable('VITE_API_URL');

    return <div>API URL: {apiUrl}</div>;
}

// Using the utility function
function AppWithUtility() {
    const { VITE_API_URL } = ensureRequiredEnvironmentVariables({
        location: 'App',
        requiredVariables: ['VITE_API_URL'],
    });

    return <div>API URL: {VITE_API_URL}</div>;
}

Types

// ESM
import {
    IEnvironmentConfig,
    IEnvironmentProcessor,
    IStandardEnvironmentValidator,
} from 'flixburst-environment-variables';

// CJS
// const { IEnvironmentConfig, IEnvironmentProcessor, IStandardEnvironmentValidator } = require('flixburst-environment-variables');

export interface IEnvironmentConfig {
    readonly location: string;
    readonly requiredVariables: string[];
}

export interface IEnvironmentProcessor {
    get(key: string): string | undefined;
}

export interface IStandardEnvironmentValidator {
    validate(name: string, value: string | undefined): void;
}

API Reference

Environment

getInstance(config: IEnvironmentConfig): Environment

Creates or returns the singleton instance of the Environment class.

const env = Environment.getInstance({
    location: 'my-app',
    requiredVariables: ['API_KEY'],
});

getVariable(name: string): string

Retrieves a single environment variable.

const apiKey = env.getVariable('API_KEY');

getVariables<T extends Record<string, string>>(variableNames: string[]): T

Retrieves multiple environment variables.

const { API_KEY, DATABASE_URL } = env.getVariables(['API_KEY', 'DATABASE_URL']);

getRequiredVariables(): readonly string[]

Returns the list of required variables.

const required = env.getRequiredVariables();

reset(): void

Clears the environment cache and resets the singleton instance.

Environment.reset();

getVariableSource(key: string): string

Gets the source of an environment variable.

const source = Environment.getVariableSource('API_KEY');
// Returns: 'process' | 'vite' | 'fallback' | 'unknown'

Utility Functions

ensureRequiredEnvironmentVariables(params: IEnvironmentConfig): Record<string, string>

A convenience function that gets all required environment variables in one call.

const envVars = ensureRequiredEnvironmentVariables({
    location: 'my-app',
    requiredVariables: ['API_KEY', 'DATABASE_URL'],
});

Error Handling

The package throws descriptive errors when:

  • Required environment variables are missing
  • Environment variables are empty
  • Invalid configuration is provided

Example error message:

Error: Environment variable "API_KEY" is missing or empty

License

MIT