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

@mostajs/config

v1.0.0

Published

Environment variable loader with MOSTA_ENV profile cascade — one .env, multiple profiles, silent fallback

Readme

@mostajs/config

Author: Dr Hamid MADANI <[email protected]> License: AGPL-3.0-or-later

Environment variable loader with profile cascade for the MostaJS ecosystem. One .env file, multiple profiles (TEST, DEV, STAGING, PROD), switched via a single MOSTA_ENV variable.

Install

npm install @mostajs/config

Why

Instead of juggling .env.test, .env.development, .env.production and forgetting to sync them, keep one .env with profile-prefixed overrides.

# .env — commit the non-secret keys
MOSTA_ENV=TEST                   # active profile

DB_DIALECT=sqlite                # plain default (also the TEST default)
SGBD_URI=./data.sqlite

DEV_DB_DIALECT=postgres
DEV_SGBD_URI=postgres://localhost:5432/devdb

PROD_DB_DIALECT=mongodb
PROD_SGBD_URI=${MONGO_ATLAS_URI} # secrets come from the orchestrator

Resolution cascade (first non-empty wins) :

  1. ${MOSTA_ENV}_${key}
  2. ${key}
  3. fallback arg
  4. undefined

Usage

import { getEnv, getEnvBool, getEnvNumber, getCurrentProfile } from '@mostajs/config';

// String with fallback
const dialect = getEnv('DB_DIALECT', 'sqlite');

// Boolean (only 'true' — case-insensitive — returns true)
const showSql = getEnvBool('DB_SHOW_SQL', false);

// Number with fallback
const poolSize = getEnvNumber('DB_POOL_SIZE', 10);

// Diagnostic
console.log(`Running in profile: ${getCurrentProfile() ?? 'none'}`);

Silent fallback guarantee

The loader never throws on missing keys. If a profile override is absent, it silently falls back to the plain variable or to the fallback argument. Callers decide whether undefined is a fatal condition.

process.env.MOSTA_ENV = 'STAGING';
// Neither STAGING_REDIS_URL nor REDIS_URL defined
getEnv('REDIS_URL')                 // undefined (no throw)
getEnv('REDIS_URL', 'redis://...')  // 'redis://...' (fallback)

Empty strings are treated as unset

To avoid accidental blank values silently propagating, an empty string in a profile override falls through to the plain variable :

TEST_DB_DIALECT=
DB_DIALECT=sqlite
getEnv('DB_DIALECT')  // 'sqlite', not ''

Whitespace in MOSTA_ENV is trimmed

MOSTA_ENV=  TEST

Resolves to profile TEST. getCurrentProfile() returns 'TEST'.

Naming convention

  • Profile name → uppercase (TEST, DEV, PROD, STAGING)
  • Variable name → UPPER_SNAKE_CASE (DB_DIALECT, SGBD_URI, REDIS_URL)
  • Profiled key → {PROFILE}_{VARIABLE} — underscore separator (TEST_DB_DIALECT, not TEST.DB_DIALECT because the dot is rejected by POSIX shells)

Testing

npm run build
npm test

License

AGPL-3.0-or-later. See LICENSE.