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

@danielres/le-config

v0.0.11

Published

A simple config handler and validator for all your projects and environments.

Downloads

17

Readme

le-config

A simple config handler and validator for all your projects and environments.

travis build Coverage Status

Your no-brainer/easy/secure/lightweight/DRY config maker.
Zero dependencies.

Why

It is a very common practice, and a highly recommended one, to store config in the environment.

Very well, but quickly, some limitations and gotchas appear, especially when having a significant number of config vars, as well as many environments to manage (local development, test, CI, multiple staging versions, production,...).

The becomes very error-prone, as it is easy to forget setting environment variables properly across all these different contexts. Even locally, when switching between local branches.

What makes it worse, is that forgetting to define environment variables rarely prevents the app from running or building. This can easily let problems slip unnoticed into the different environments, notably into production.

A common, better practice

A common solution you might be familiar with is to centralize all config management in a unique config.js, solely responsible for reading environment variables, and validating them. This approach is already a huge win as, done properly, it can solve most, if not all problems desribed above.

But this introduces new downsides, like:

  1. reinventing the wheel for each new project, writing your own validators, or:

  2. relying on external validation libraries, which are most often overkill for this specific use case

  3. A lack of DRYness, like demonstrated in the pseudo-code below:

    // pseudo-code
    const config = {
      FOO: process.env.FOO,
      BAR: process.env.BAR,
    };
    
    const validators = {
      FOO: someValidator,
      BAR: someOtherValidator,
    };
    
    export default validate(config, validators);

    While this offers more safety, we can see how it can be easily cumbersome and error-prone, as for every config property added or removed, we need to keep the validators in sync manually.

Enter le-config

le-config aims to solve all the problems listed above.

  1. It is a very lightweight micro-library, with no external dependencies.
  2. It packs the most common validators, but allows easy customization. You can easily write your own validators (and use an external validation library if you choose to).
  3. It offers a very DRY and minimal syntax.

Usage

  1. Create a new file config.js

  2. Import or require le-config as follow:

    // config.js (ES6)
    import { checks, makeConfig } from "@danielres/le-config";

    or

    // config.js (CommonJS)
    const { checks, makeConfig } = require("@danielres/le-config");
  3. Generate a secure, centralized config for you app:

    // config.js (ES6)
    import { checks, makeConfig } from "@danielres/le-config";
    
    const REGEXP_EMAIL = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
    const emailCheck = checks.string.regexp(REGEXP_EMAIL);
    
    export default makeConfig({
      port: [process.env.PORT, checks.int.port()],
      flags: {
        feature1: [process.env.FLAGS_FEATURE1, checks.boolean.boolean],
        feature2: [process.env.FLAGS_FEATURE2, checks.boolean.boolean],
      },
      emails: {
        admin: [process.env.EMAILS_ADMIN, emailCheck],
        editor: [process.env.EMAILS_EDITOR, emailCheck],
      },
    });
  4. Use the resulting secure config thourought your app:

    // src/index.js (ES6)
    import express from "express";
    import config from "./config";
    
    const { emails, flags, port } = config;
    
    const app = express();
    
    if (flags.feature1) console.log("Feature1 enabled.");
    if (flags.feature2) console.log("Feature2 enabled.");
    
    app.get("/", (req, res) =>
      res.send(`Hello world! Contact the admin at: ${emails.admin}`)
    );
    
    app.listen(port, () => {
      console.log(`Listening on http://localhost:${port}`);
    });
  5. Fail FAST when the config is not valid.

    This prevents your app from being started or deployed if any check fails, while offering helpful console output.

    • Example 1: If your app has a build step:

      // in package.json
      {
        "scripts": {
          "prebuild": "node ./config.js",
          "dev": "node ./config.js && nodemon src",
          "start": "node ./config.js && node src"
        }
      }
    • Example 2: If your app has no build step:

      // in package.json
      {
        "scripts": {
          "dev": "node ./config.js && nodemon src",
          "start": "node ./config.js && node src"
        }
      }

Example "fail fast" terminal output

[nodemon] starting `node -r esm ./index.js`

╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌
 3 config validation errors:
 ✗ port: should be an integer within 1025 and 65534 | Actual: 8000000
 ✗ feature1: should be a boolean | Actual: oopsie
 ✗ feature2: should be a boolean | Actual: undefined
╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌

[nodemon] app crashed - waiting for file changes before starting...