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 🙏

© 2026 – Pkg Stats / Ryan Hefner

baher-dotenv

v1.1.2

Published

A lightweight TypeScript library for type-safe Node.js environment configuration.

Downloads

265

Readme

baher-dotenv

Type-safe environment configuration loader for Node.js.

Node.js TypeScript NX Backend Package License


🇺🇸 English

Overview

baher-dotenv is a TypeScript library for Node.js backend applications.

It allows you to define environment variables using a typed configuration object, then load these values into process.env.

The main goal is to make environment configuration more structured, centralized, and type-safe.


Installation

npm install baher-dotenv

Usage

import { baherEnvConfig, baherLoadEnv, ENV_TYPE } from 'baher-dotenv';

const envConfig = baherEnvConfig({
  APP_NAME: {
    type: ENV_TYPE.String,
    value: 'orders-api',
  },

  APP_PORT: {
    type: ENV_TYPE.Number,
    value: 3000,
  },

  ENABLE_ELK: {
    type: ENV_TYPE.Boolean,
    value: true,
  },
});

baherLoadEnv(envConfig);

After calling baherLoadEnv, the values will be available inside process.env:

process.env.APP_NAME;   // "orders-api"
process.env.APP_PORT;   // "3000"
process.env.ENABLE_ELK; // "true"

API

ENV_TYPE

A constant object used to define the type of each environment variable.

ENV_TYPE.String
ENV_TYPE.Number
ENV_TYPE.Boolean

baherEnvConfig(config)

Defines a typed environment configuration.

const envConfig = baherEnvConfig({
  APP_PORT: {
    type: ENV_TYPE.Number,
    value: 3000,
  },
});

If the value does not match the selected type, TypeScript will show an error.

Example:

const envConfig = baherEnvConfig({
  APP_PORT: {
    type: ENV_TYPE.Number,
    value: '3000', // TypeScript error
  },
});

baherLoadEnv(config, options?)

Loads the provided configuration into process.env.

baherLoadEnv(envConfig);

By default, existing values inside process.env are not overwritten.

To allow overriding existing values:

baherLoadEnv(envConfig, {
  override: true,
});

Supported Types

Currently supported types:

string
number
boolean

All values are converted to strings before being added to process.env, because Node.js environment variables are string-based.


Build

npx nx build baher-dotenv

Release

From the workspace root:

npm run release

Project Structure

dotenv/
  src/
    index.ts
    lib/
      core/
        constants/
        functions/
        types/
  README.md
  package.json

License

MIT License.

See LICENSE.


🇪🇬 العربية

نظرة عامة

baher-dotenv هي مكتبة موجهة لتطبيقات Node.js.

تساعدك المكتبة على تعريف متغيرات البيئة باستخدام TypeScript بشكل منظم وآمن من ناحية الأنواع، ثم تحميل هذه القيم داخل process.env.

الهدف الأساسي من المكتبة هو جعل إعدادات البيئة أكثر تنظيمًا ومركزية وتقليل الأخطاء الناتجة عن التعامل مع القيم كنصوص غير واضحة.


التثبيت

npm install baher-dotenv

طريقة الاستخدام

import { baherEnvConfig, baherLoadEnv, ENV_TYPE } from 'baher-dotenv';

const envConfig = baherEnvConfig({
  APP_NAME: {
    type: ENV_TYPE.String,
    value: 'orders-api',
  },

  APP_PORT: {
    type: ENV_TYPE.Number,
    value: 3000,
  },

  ENABLE_ELK: {
    type: ENV_TYPE.Boolean,
    value: true,
  },
});

baherLoadEnv(envConfig);

بعد تنفيذ baherLoadEnv سيتم إضافة القيم داخل process.env:

process.env.APP_NAME;   // "orders-api"
process.env.APP_PORT;   // "3000"
process.env.ENABLE_ELK; // "true"

الواجهة البرمجية

ENV_TYPE

ثابت يستخدم لتحديد نوع كل متغير بيئة.

ENV_TYPE.String
ENV_TYPE.Number
ENV_TYPE.Boolean

baherEnvConfig(config)

تستخدم لتعريف إعدادات البيئة بطريقة typed.

const envConfig = baherEnvConfig({
  APP_PORT: {
    type: ENV_TYPE.Number,
    value: 3000,
  },
});

إذا كانت قيمة value لا تطابق النوع المحدد في type، سيظهر خطأ من TypeScript.

مثال غير صحيح:

const envConfig = baherEnvConfig({
  APP_PORT: {
    type: ENV_TYPE.Number,
    value: '3000', // TypeScript error
  },
});

baherLoadEnv(config, options?)

تستخدم لتحميل القيم داخل process.env.

baherLoadEnv(envConfig);

بشكل افتراضي، إذا كانت القيمة موجودة مسبقًا داخل process.env فلن يتم استبدالها.

للسماح باستبدال القيم الموجودة:

baherLoadEnv(envConfig, {
  override: true,
});

الأنواع المدعومة

الأنواع المدعومة حاليًا:

string
number
boolean

يتم تحويل كل القيم إلى string قبل إضافتها إلى process.env، لأن متغيرات البيئة في Node.js تعتمد على النصوص.


بناء المكتبة

npx nx build baher-dotenv

إصدار المكتبة

من جذر المشروع:

npm run release

هيكل المشروع

dotenv/
  src/
    index.ts
    lib/
      core/
        constants/
        functions/
        types/
  README.md
  package.json

الترخيص

رخصة MIT.

راجع ملف LICENSE.