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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@lafferty-lounge/config

v0.1.0

Published

A simple configuration provider

Readme

@lafferty-lounge/config

The lafferty-lounge config package is a simple configuration management package. It handles reading from a file, reading from stdin, environment variables, and command line arguments. It parses everything as yaml so you can use JSON if that's your style.

Usage

test.js

const Config = require('@lafferty-lounge/config');
const config = new Config('NODE_CONFIG', [
  ['option-flag,o', 'default-value'], // list the arguments that you want to parse
  ['other-arg']
]);
config.fetch()
  .then(parsedConfig=>{
    console.log(parsedConfig); // { verbosity: null }
  });

config.yaml

option-flag: bar

CLI

echo '{"option-flag": "foo"}' | node test.js -c -         # {'option-flag': 'foo', ...} read from stdin
echo '{"option-flag": "foo"}' | node test.js --config=-

node test.js -c config.yaml                               # {'option-flag': 'bar', ...} read from file
node test.js --config=config.yaml

node test.js -c '{"option-flag": "inline"}'               # {'option-flag': 'inline', ...} read from argv
node test.js --config='{"option-flag": "inline"}'

Reserved flags

  • --config
  • -c

Both -c and --config are used to tell config where to load a yaml "file" from. (stdin, inline, file)

Type of input

The config module takes several type of inputs for configuration options.

When you create a config instance you'll pass it a prefix to use for environment variables as well as an array of arguments to look for and parse.

const Config = require('@lafferty-lounge/config');
const config = new Config('NODE_CONFIG', [
  ['option-flag,o', 'default-value'], // list the arguments that you want to parse
  ['other-arg']
]);
config.fetch()
  .then(parsedConfig=>{
    console.log(parsedConfig); // { 'option-flag': null }
  });

In the previous test.js file you'll notice 'option-flag,o'. That is the option that the config module will attempt to find in your various configurations.

The option-flag key is what config will search for. The c after the comma is the shorthand flag to look for on the command line.

The second item in the option-flag array is the default value to use if no options are found.

NODE_CONFIG will be prefixed to environment variables when parsing options. I.e. for option-flag we'll look for the environment variable NODE_CONFIG_CLI_ARG.

Command Line Arguments

Command line arguments are will be referenced by the same name (dashes included) that you use in your options array. I.e. we'll look for node test.js --option-flag in the following:

const config = new Config('NODE_CONFIG', [
  ['option-flag,o', 'default-value']
]);

Shorthand Command Line Arguments

Shorthand command line arguments are optional and are paired with a long hand flag. I.e. we'll end up with { 'option-flag': 'bar' } when we run node test.js -o bar

test.js

const config = new Config('NODE_CONFIG', [
  ['option-flag,o', 'default-value']
]);

Environment Variables

When you create a config instance you will pass it a prefix as the first argument. This prefix will be prepended to your options when searching for environment variables.

I.e. We'll look for NODE_CONFIG_OPTION_FLAG using the folling configuration:

test.js

const config = new Config('NODE_CONFIG', [
  ['option-flag,o', 'default-value']
]);

Config Files (--config, -c)

Config will parse config files as yaml so you can pass yaml or JSON. Pass the -c or --config arguments when running your application to tell config that you want to load a file.

available --config options

  • -
  • /filepath
  • {"inline": "json"}

Default Values

You can define default values for config options if none of the available places to search have a value defined for them.

We'll end up with { 'option-flag': 'default-value' } if we don't provide any configuration options to the application.

test.js

const config = new Config('NODE_CONFIG', [
  ['option-flag,o', 'default-value']
]);

Precedence

Values take priority from top to bottom in the following order:

  1. command line arguments
  2. command line shorthand
  3. environment variables
  4. config file
  5. defaults

Example:

test.js

const Config = require('@lafferty-lounge/config');
const config = new Config('CONFIG', [
  ['test-key']
]);
config.fetch()
  .then(parsedConfig=>{
    console.log(parsedConfig);
  });
export CONFIG_TEST_KEY=foo
node test.js                  # { 'test-key': 'foo' }
node test.js --test-key bar   # { 'test-key': 'bar' } command line argument takes precedence here