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

config-loaders

v0.3.0

Published

Collect and parse configuration from different sources

Readme

config-loaders

Collect and parse configuration from different sources

Examples

Load .env file from current working or upper directory:

# .env

STR=value
NUM=42
BOOL=true
import { DotEnvLoader } from "config-loaders";

const loader = new DotEnvLoader();
const value = loader.getValue();

/* value is:
{
  STR: "value",
  NUM: 42,
  BOOL: true,
}
*/

Load environment variables:

import { EnvLoader } from "config-loaders";

const loader = new EnvLoader({
  filterNames: ["VAR1", "VAR2"],
});

const value = loader.getValue();

/*
value contains only VAR1 and VAR2 variables
(if they exist in the `process.env`)
*/

Load from multiple sources:

import {
  DotEnvLoader,
  EnvLoader,
  LoadersPack,
  ValueLoader,
} from "config-loaders";

const loader = new LoadersPack([
  new DotEnvLoader(),
  new EnvLoader(),
  new ValueLoader({ value: { TEST: true } }),
]);

const value = loader.getValue();

/*
value is values from .env file overriden by values
from process.env and { TEST: true } object.
*/

Install

npm install config-loaders

API

Abstract classes

abstract class Loader

Class representing a loader.

The process of obtaining a value is divided into three stages:

  1. Loading
  2. Parsing
  3. Transformation

The derived class must implement methods of stages 1 and 2.

Stage 3 method returns unchanged value by default and can be omitted.

Methods:

async getValue(): Promise<JsonObject>

The main method for getting the loader's value. Should return a serializable object.

abstract load(): Promise<JsonValue>

Should implement the logic for obtaining raw value.

abstract parse(rawValue: JsonValue): Promise<JsonObject>

Should implement the logic for parsing the raw value.

async transform(parsedValue: JsonObject): Promise<JsonObject>

May optionally describe the logic for converting a parsed value to its final form.

abstract class FileLoader

Base class for implementing file loaders. Includes logic for search the file by traversing directory tree up.

Options:

fileName?: string | (() => string)

Name of the file to be loaded.

default: "config"

fileDir?: string | (() => string)

Directory where the file search starts.

default: process.cwd()

findUp?: boolean

Try to find the file in upper directories.

default: true;

stopAt?: string | (() => string)

Directory where the file search stops.

default: path.parse(fileDir).root

fileEncoding?: BufferEncoding

Encoding of the file.

default: "utf-8"

failSilently?: boolean

Don't throw an error if the file isn't found.

default: false

Loaders

class DotEnvLoader

Loader that utilizes dotenv library for parsing files contain environment variables settings. Checks if there are expandable variables and expand them using dotenv-expand library. The default parser also converts string representations of primitive types to their proper types.

Requires dotenv package to be installed.

Requires dotenv-expand package to be installed in the case of expandable variables processing.

Options:

FileLoader options with default fileName .env:

expandVariables?: boolean

Whether to expand variables.

default: true;

parserOptions?: JsonStringValuesParserOptions

Parser options. See the list here.

default: {}

class EnvLoader

Loader that reads process.env object. The default parser converts string representations of primitive types to their proper types.

Options:

parserOptions?: JsonStringValuesParserOptions

Parser options. See the list here.

default: {}

filterNames?: string[] | ((name: string) => boolean) | false

Filter properties in the final object by its names.

default: false

class LoadersPack

Loader that takes an array of loaders and merges the values loaded using them.

Constructor parameters:

loaders: Loader[] – Required

Loaders list

class YamlLoader

Loader for loading .yaml files.

See FileLoader options for options list. Default filename is config.yaml.

class ValueLoader

Loader that takes a static value or a function returning the value.

Options:

value: T | (() => T) – Required

Value itself or a factory function returning the value.

License

Licensed under the MIT license. Copyright (c) 2023-present Vladislav Alexeev