Socket
Socket
Sign inDemoInstall

config-dug

Package Overview
Dependencies
5
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    config-dug

Config loader with support for AWS Secrets Manager


Version published
Weekly downloads
5.9K
decreased by-7.51%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

Config Dug

Config Dug

Config loader with support for AWS Secrets Manager.

TypeScript 3.4.3

Usage

Installation

yarnnpm
yarn add config-dugnpm 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.kanye.rest/'
};
// config.default.js
module.exports = {
  API_ENDPOINT: 'https://api.kanye.rest/'
};

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

  1. config.default.{ts|js}
  2. config.${NODE_ENV}.{ts|js}
  3. config.local.{ts|js}
  4. AWS Secrets Manager
  5. 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);
// https://api.kanye.rest/
// app.js
const config = require('config-dug');

console.log(config.API_ENDPOINT);
// https://api.kanye.rest/

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 name of the secret to look up:

// config.default.ts
export default {
  AWS_SECRETS_MANAGER_NAME: 'production/myapp/config',
  API_ENDPOINT: 'https://api.kanye.rest/'
}

In addition to specifying the secret name you can also provide a region using the AWS_SECRETS_MANAGER_REGION or awsSecretsManagerRegion setting:

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

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: yarn
  4. Run tests: yarn test

Credits

This project was inspired by config3 and config4.

Keywords

FAQs

Last updated on 22 Apr 2019

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc