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 🙏

© 2024 – Pkg Stats / Ryan Hefner

mxd-config

v3.2.0

Published

Loads the config files if available depending on the environment

Downloads

2

Readme

Description

Files which will be required (all files can be defined as JSON and .js CommonJS module):

  • If environment is undefined or 'development':
    1. /config/all
    2. /config/development
    3. /config/properties
  • Else:
    1. /config/all
    2. /config/properties

The later required files overwrites the others. If an attribute is defined as array, the complete attribute will be overwritten.

Example

const config = require('mxd-config')();
// if the environment is later needed use 'config.environment' 

Configuration

The environment will be defined by NODE_ENV but can be overwritten:

const config = require('mxd-config')('development');

Additional filenames (located in the config directory) can be defined, which also will be loaded:

const config = require('mxd-config')(['lambda']);

If both (environment and additional filenames) are needed, use a config object:

const config = require('mxd-config')({ 
  environment: 'development',
  filenames: ['lambda'], 
});

dotenv

This module silently loads /.env.<NODE_ENV> configs in the project root, e.g. /.env.production if one is found. As a result, we can simply start the app using NODE_ENV=test node app.js which loads /.env.test into the config.

For development purposes, the module also silently loads a "generic" /.env, config regardless of the environment. The variables contained here override those in /.env.<NODE_ENV>.

Environment Getters

Using environment getters, we can get environment variables and cast a type and a default value on them:

const { getBool, getInt, getList, getStr } = require('mxd-config').util;

module.exports = {
  myBool: getBool('MY_BOOL', true),
  myInteger: getInt('MY_INT', 123),
  myString: getStr('MY_STRING', 'foo'),
  myList: getList('MY_LIST', ['foo', 'bar', 'baz'])
};

With no environment variables set, this outputs

{
  myBool: true,
  myInteger: 123,
  myString: 'foo',
  myList: ['foo', 'bar', 'baz']
}

Here's an example .env.development file:

MY_BOOL=off
MY_INT=456
MY_STRING=bar
MY_LIST=baz|bar|foo

This outputs

{
  myBool: false,
  myInteger: 456,
  myString: 'bar',
  myList: ['baz', 'bar', 'foo']
}