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

config-dug

v1.9.0

Published

Config loader with support for AWS Secrets Manager

Downloads

26,225

Maintainers

niloofarshsniloofarshsmahtab.khanmahtab.khansamin_farajiansamin_farajianneo-tamika-taylorneo-tamika-taylorjimi487jimi487divanshudivanshumaiko.trindademaiko.trindadeneo-ahmed-jamaneo-ahmed-jamaneo-eason-changneo-eason-changmganzneomganzneoneo-colin-hanlon-dearmanneo-colin-hanlon-dearmanneo-edimar-cardosoneo-edimar-cardosoneo-chris-nobleneo-chris-nobleneo-will-parkerneo-will-parkerneo-paula-grangeironeo-paula-grangeirogaulfordgaulforddanielafekhume-neodanielafekhume-neoneo-lior-ben-shaharneo-lior-ben-shaharneo-diego-nunesneo-diego-nunestim-neo2tim-neo2antonio.canabravaantonio.canabravaneo.eduardoyuidyneo.eduardoyuidyneo-oleksandr-yanchenkoneo-oleksandr-yanchenkoneo-barry-lineo-barry-lidesmond-maloneydesmond-maloneyneo-elgiz-abbasovneo-elgiz-abbasovnikita-syrotenkonikita-syrotenkoneo-bclausineo-bclausidustinn1235dustinn1235neo-peter-spanglerneo-peter-spanglerneo-rivan-motaneo-rivan-motaneo-daniel-brennanneo-daniel-brennanneo-matt-feliceneo-matt-feliceneo-rameez-virjineo-rameez-virjimatt-armstrongmatt-armstrongrajanatneorajanatneoneo-zhaoquan-zhangneo-zhaoquan-zhangalejandrogarbialejandrogarbironellgarciaronellgarciaedward.nazarovedward.nazarovannakumovaannakumovaleah-is-offlineleah-is-offlineneo-shruti-goyalneo-shruti-goyalfelipe.minettofelipe.minettotunde-neotunde-neoneo-shubham-patelneo-shubham-patelbiancaballenabiancaballenajadondubyjadondubymsalamamsalamaishmeet.rayatishmeet.rayatneo-bryce-brandfordneo-bryce-brandfordneo-ricardo-gomezneo-ricardo-gomezneobot1neobot1neo-dakota-chattneo-dakota-chattlucasjohannsonlucasjohannsonneo-travis-friesenneo-travis-friesenmike.himbeault-neomike.himbeault-neoraul.ribeiroraul.ribeiroanhtranneoanhtranneolucachameckilucachameckiamievishwaamievishwaneo-matias-wengielneo-matias-wengielneo-ahmed-seifelnasrneo-ahmed-seifelnasrrhullyamrhullyamdas-bossdas-bosskennethcolinakennethcolinamarvindeleonmarvindeleonneo-miguel-castroneo-miguel-castroneo-dione-silvaneo-dione-silvahanna.tkachenkohanna.tkachenkonico-connornico-connorroman.mnatsakanianroman.mnatsakanianbriancruzbriancruzamjad-mahfoud-neoamjad-mahfoud-neoneoauderesantosneoauderesantosnitin.madannitin.madanmohpormohporpunit.patelpunit.patelbrayden_sc_neobrayden_sc_neoanna_benemanskaiaanna_benemanskaiahrishikeshkalehrishikeshkalekyle-elyk-neokyle-elyk-neomichelepipernimichelepipernineo-youre_penaneo-youre_penaneo-michal-kowalneo-michal-kowalniconeimanniconeimanneodiegobeltranneodiegobeltranstburkestburkemarcelo.matosmarcelo.matosmatheusicaromatheusicaromaiahneomaiahneorjberryrjberrymohamedalhammoudmohamedalhammoudneo-hasanpreetsinghneo-hasanpreetsinghjcavalcantijcavalcantistephanie-wang-neostephanie-wang-neokaelanneofinancialkaelanneofinancialvinicius-barcelosvinicius-barcelosbenx-neobenx-neomhowitt-neomhowitt-neomalcolm-neomalcolm-neoneo-seol-kimneo-seol-kimbrentcambrentcamteena_teena_deankimdeankimherculesjrherculesjrmatthew.belfordmatthew.belfordrishbarrishbarneo-baonguyenneo-baonguyencaio.andradecaio.andradeluan.leluan.ledennisbartheldennisbarthellavanya.mohanlavanya.mohandhruvangdhruvangneo-rodrigoravalneo-rodrigoravaljoeljwoodjoeljwoodnahom-neonahom-neostefan.amyottestefan.amyottetimothy.couch.neofinancialtimothy.couch.neofinancialscottkayeneoscottkayeneoomolaraomolaraar-iesar-iescjnewmancjnewmanvidalrmrzvidalrmrzrnetto46rnetto46iansuiansudarrenpicard25darrenpicard25maxgoomaxgoostschmaltzstschmaltzusernamesebusernameseberic.zaporzan.neoeric.zaporzan.neolucasparreiralucasparreiralewishorwoodlewishorwoodcraigsiemenscraigsiemensdiegobmydiegobmyjoelsimpsonjoelsimpsonjooh-leejooh-leekasrababaeikasrababaeiu2v22u2v22johnclendvoyjohnclendvoydemaestrodemaestrodaylan.lawdaylan.lawneo-stephenneo-stephenneogibsonneogibsonberakiberakivrochamaaiavrochamaaiad_fenniakd_fenniakadamtranquillaadamtranquillanehasingh1801nehasingh1801lucaslongarinilucaslongarinierozonachierozonachifaddoulfaddoulnpoltz-neonpoltz-neo

Readme

Config Dug

Build status coverage codecov TypeScript 3.7.2

Config Dug

Config loader with support for AWS Secrets Manager.

Usage

Installation

| yarn | npm | | --------------------- | ------------------------ | | yarn add config-dug | npm install config-dug |

Create your config files

config-dug looks in several places for your config, including config files in your project, environment variables and AWS Secrets Manager. config-dug allows you to write your config files in either TypeScript or JavaScript. You are expected to export a default object from your config file:

// config.default.ts
export default {
  API_ENDPOINT: 'https://api.example.com/',
};
// config.default.js
module.exports = {
  API_ENDPOINT: 'https://api.example.com/',
};

Environment specific config files are loaded based on the value of the APP_ENV or NODE_ENV environment variables. If APP_ENV is present it will take precedence over NODE_ENV.

Settings from these different sources are merged together into a single config object in the following order:

  1. config.default.{ts|js}
  2. config.${APP_ENV|NODE_ENV}.{ts|js}
  3. config.${APP_ENV|NODE_ENV}.local.{ts|js}
  4. config.local.{ts|js}
  5. AWS Secrets Manager
  6. Environment variables

By default your config files need to be placed in the root directory of your project. If you want to keep config files in a different directory see Customizing Config Loading.

Import config

Import config-dug anywhere in your code where you want to access your config. All of your settings are available on the imported object:

// app.ts
import config from 'config-dug';

console.log(config.API_ENDPOINT);
// app.js
const config = require('config-dug').default;

console.log(config.API_ENDPOINT);
// https://api.example.com/

:warning: You must use require('config-dug').default in JavaScript files. If you exclude .default Config Dug will not work.

Environment Variables

config-dug will add all your environment variables to the config object. This can have unintended consequences if one of your config keys has the same name as an existing, unrelated environment variable.

:warning: config-dug is only intended to be used on the server. Your server already has access to your full environment in process.env. If you use config-dug in server rendered client applications you risk exposing your server's environment to the client.

Using AWS Secrets Manager

In order to use AWS Secrets Manager you have to add a AWS_SECRETS_MANAGER_NAME or awsSecretsManagerName setting to your config that specifies the names of the secrets to look up:

// config.default.ts
export default {
  AWS_SECRETS_MANAGER_NAME: 'production/myapp/config',
  API_ENDPOINT: 'https://api.example.com/',
};

If you need to read from multiple secret buckets, AWS_SECRETS_MANAGER_NAMES takes a comma separated list to allow connection to multiple secrets in AWS Secrets Manager. Each secret from the list is evaluated in order mean that if a specific key appears in two secrets the value will be overwritten by the last secret in the list.

// config.default.ts
export default {
  AWS_SECRETS_MANAGER_NAMES: 'production/myapp/config,production/myapp/another-config',
  API_ENDPOINT: 'https://api.example.com/',
};

In addition to specifying the secret name you can also provide a region using the AWS_SECRETS_MANAGER_REGION or awsSecretsManagerRegion setting. The connection timeout in milliseconds can also be specified using the AWS_SECRETS_MANAGER_TIMEOUT or awsSecretsManagerTimeout setting:


// config.default.ts
export default {
  AWS_SECRETS_MANAGER_NAME: 'production/myapp/config',
  AWS_SECRETS_MANAGER_REGION: 'us-west-2',
  AWS_SECRETS_MANAGER_TIMEOUT: 2000
  API_ENDPOINT: 'https://api.example.com'
};

The default region is us-east-1 and the default connection timeout is 5000ms.

Config Dug will warn if it detects invalid config values. Invalid values include:

  • undefined
  • null
  • the string 'undefined'
  • an empty string

This package uses the aws-sdk internally. Refer to their documentation for information about authentication, configuring a default region and configuring access control for AWS Secrets Manager.

Advanced

Customizing Config Loading

If you want to load config files from a directory other than the project root you can import the loadConfig function and use it directly.

import { loadConfig } from 'config-dug';

loadConfig('config');

This will import your config files from the config directory. The path you specify must be relative to your project root.

Debugging

config-dug uses the debug library. To print debug messages for config-dug set DEBUG=config-dug.

Contributing

Running Tests

  1. Fork this repo
  2. Clone the forked repo
  3. Install dependencies: npm install OR npm i
  4. Run tests: npm run test

Publishing

  1. Update the version in package.json
  2. Add a CHANGELOG entry
  3. Commit your changes
  4. Run npm pack to see what will be published then delete the .tgz file that was created
  5. Run npm publish
  6. Create a release on GitHub. Use the version as the tag and release name. For example for version 1.0.0 the tag and release name would be v1.0.0.

Credits

This project was inspired by config3 and config4.