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

node-application-config

v0.2.0

Published

Application config package that provides a config object with support for local overrides and environmental overrides

Downloads

1,024

Readme

node-application-config

Package to provide application config with local config and environment support. This package allows you to simply override config variables by defining local config files or environment variables.

Also nodeEnv, and isDebug are set based on NODE_ENV, which can be used in your code later on.

A bunch of badges

Build Status npm Coverage status license

Features

Parse environment variables

If you want to parse other environmental variables into your application config, and you cannot (or you don't wanna) use process.env you can use the parsing feature. If you declare a config variable with the following pattern: ${ENV_VAR_NAME}, the config application will match it to the corresponding environment variable.

Example

export TEST_ENV_VAR=foobar
{
  "db": {
    "host": "${TEST_ENV_VAR}"
  }
}

In this case, config.db.host will be parsed to "foobar".

Require json file

If you need to require a json - yes only json, 'cause securty - file, you can do that with a special pattern. You need to use a relative filepath. If any error happens during the require process, the variable will have the value REQUIRE_ERROR and will have the error message attached.

The pattern for this feature is: !{filepath.json}.

Example

foobar.json

{
  "hello": "world" 
}

config.json

{
  "foobar": "!{./foobar.json}"
}

Results in:

{
  "foobar": {
    "hello": "world"
  }
}

Parse environment array variables

If you want to overwrite an array with a config variable (maybe you have a list of languages), you can overwrite the array with the following syntax:

ARRAY_ENV=str1|str2|str3

This feature is only necessary if you want to overwrite an array with environment variables, since you can use arrays in the config.json and the config.local.json files. If you want to overwrite a variable with a single element array or even an empty array, you can simply pass str1| for a single element array or | for an empty array.

Example

export app_config_arrayType=string1|string2|string3
export app_config_emptyArrayType=|
export app_config_singleElementArrayType=string1|

Results in:

{
  "arrayType": [
    "string1",
    "string2",
    "string3"
  ],
  "emptyArrayType": [],
  "singleElementArrayType": [
    "string1"
  ]
}

Usage

var appConfig = require('node-application-config'),
    config = appConfig(options);

Configuration

options is a hash with the following config variables:

startupPath

Base path for the application and for the config package to search for configurations

default: process.cwd()

configName

Name of the base configuration

default: config.json

localConfigName

Name of the local configuration (which overwrites the base config, but is not necessarily in the version control)

default: config.local.json

envConfigName

Name of the environment configuration (which overwrites the base config, but is not necessarily in the version control) ENV will be replaced with process.env.NODE_ENV!

default: config.ENV.json

environmentPrefix

Prefix for environment variables that overwrite the configurations

default: app_config_

environmentDelimiter

Which character is used for splitting the environment variables after the prefix is removed.

default: _

enableStateVariables

Enable the automatically set nodeEnv, isDebug, isStage and isProduction config variables, based on NODE_ENV. If no NODE_ENV is set, development is taken as fallback value.

default: true

Priorities

When merging config variables, the following priorities are taken into account:

  1. Environment variable
  2. Local config variable
  3. Environment config file
  4. Config variable

Example

config.json

{
  "db": {
    "user": "test",
    "pass": "testPass",
    "port": "10000"
  }
}

config.local.json

{
  "db": {
      "pass": "securePass",
      "host": "localhost"
  }
}

environment variable

app_config_db_port=1337

... results in:

var appConfig = require('node-application-config'),
    config = appConfig();

config.db.user == "test";
config.db.pass == "securePass";
config.db.host == "localhost";
config.db.port == 1337;