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

@munesoft/envx

v1.0.1

Published

One-line .env loader, validator, and type-safe config for Node.js

Readme

@munesoft/envx

One-line .env loader, validator, and type-safe config for Node.js.

npm version license node


Why envx?

Every Node.js app depends on environment variables — but most apps:

  • Crash unexpectedly due to missing variables
  • Treat everything as strings (even ports and flags)
  • Lack validation and sensible defaults
  • Fail silently in production

envx fixes this in one line.


Install

npm install @munesoft/envx

Quick Start

Add at the very top of your app:

import "@munesoft/envx/config";

Your .env file is now loaded, validated, and type-safe. That's it.


Basic Usage

.env

PORT=3000
NODE_ENV=development
API_KEY=sk_abc123

envx.config.js

export default {
  PORT:     { type: "number",  default: 3000 },
  NODE_ENV: { type: "string",  enum: ["development", "production"] },
  API_KEY:  { type: "string",  required: true },
};

app.js

import "@munesoft/envx/config";
// process.env.PORT is now the number 3000, not the string "3000"

API

import "@munesoft/envx/config" (recommended)

Side-effect import. Loads, validates, and applies env vars before your app runs. Uses envx.config.js if present, otherwise applies smart defaults.


import envx from "@munesoft/envx"

Programmatic loader with full options:

import envx from "@munesoft/envx";

await envx({
  path: ".env.production",       // custom .env path
  override: false,               // process.env wins by default
  debug: true,                   // print resolved values
  strict: true,                  // disallow unknown vars
  schema: {
    PORT:    { type: "number",  default: 3000 },
    API_KEY: { type: "string",  required: true },
  },
});

Schema Rules

Each key in the schema supports:

| Option | Type | Description | |-------------|------------|-----------------------------------------------------| | type | string | One of string, number, boolean, url, email, json | | required | boolean | Fail if the variable is missing | | default | any | Value used when variable is absent | | enum | any[] | Restrict to a fixed set of values | | validate | function | Custom validator — return false or throw to fail |


Supported Types

| Type | Input example | Coerced to | |-----------|----------------------|-----------------------------| | string | "hello" | "hello" | | number | "3000" | 3000 | | boolean | "true", "1", "yes" | true | | url | "https://..." | "https://..." (validated) | | email | "[email protected]" | "[email protected]" (validated) | | json | '{"a":1}' | { a: 1 } (parsed) |


Error Handling

envx fails fast with clear output:

❌ ENV VALIDATION FAILED

  - API_KEY is required but missing
  - PORT must be a number (received "abc")
  - NODE_ENV must be one of ["development", "production"] (received "staging")

Config Formats

Flat (simple):

export default {
  PORT:    { type: "number", default: 3000 },
  API_KEY: { type: "string", required: true },
};

Structured (with strict mode):

export default {
  strict: true,
  schema: {
    PORT:    { type: "number", default: 3000 },
    API_KEY: { type: "string", required: true },
  },
};

Advanced Features

Custom Validators

API_KEY: {
  type: "string",
  validate: (value) => value.startsWith("sk_"),
}

JSON Variables

FEATURE_FLAGS={"beta":true,"darkMode":false}
FEATURE_FLAGS: { type: "json" }
// → { beta: true, darkMode: false }

Environment-Specific Defaults

PORT: {
  type: "number",
  default: process.env.NODE_ENV === "production" ? 80 : 3000,
}

Debug Mode

ENVX_DEBUG=true node app.js

Prints resolved values at startup (secrets are masked automatically).


CLI

# Validate your .env against envx.config.js
npx envx check

# Validate a specific .env file
npx envx check --path .env.production

# Generate a starter config from your .env
npx envx init

TypeScript

envx ships with full type definitions:

import envx from "@munesoft/envx";
import type { LoadOptions, Schema } from "@munesoft/envx";

const schema: Schema = {
  PORT:    { type: "number",  default: 3000 },
  API_KEY: { type: "string",  required: true },
};

await envx({ schema });

const port: number = process.env.PORT as unknown as number;

Zero Config Mode

No envx.config.js? No problem.

envx will:

  • Load .env automatically
  • Apply smart defaults
  • Warn on obviously missing critical variables

Security

  • Prevents undefined variables from silently crashing apps
  • Masks secrets in debug output (keys containing KEY, TOKEN, SECRET, PASSWORD)
  • Encourages explicit, validated configuration

Philosophy

Configuration should never be a source of runtime failure.

envx ensures your app starts correctly or not at all.


vs dotenv

| Feature | dotenv | envx | |---------------------|:------:|:----:| | Load .env | ✅ | ✅ | | Validation | ❌ | ✅ | | Type coercion | ❌ | ✅ | | Default values | ❌ | ✅ | | Enum enforcement | ❌ | ✅ | | Custom validators | ❌ | ✅ | | Clear error output | ❌ | ✅ | | TypeScript types | ❌ | ✅ | | CLI tools | ❌ | ✅ | | Zero-config mode | ❌ | ✅ |


License

MIT © Munesoft