Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

configeur

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

configeur

Extensible parsing of environment variables into config.

  • 1.0.2
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

configeur

This module is inspired by and borrows much of its behaviour from the excellent Konfiga module. This module removes the commandline parsing abilities of its ancestor, adds required variables, and simplifies some internal logic around custom parsers by slightly altering that part of the options API.

configeur reads in the environment and uses a spec to parse and the values found to appropriate types. It supports:

  • Type casting, with some types parsers included and API to add or replace parsers.
  • Default values when environment variables should be optional.
  • Required values when environment variables are not optional.

Usage

Configeur accepts an object which defines config variables names and how to derive them from the environment (or a default).

For example:

// Module config.js

const configeur = require('configeur');

const config = configeur({
    port: {
        defaultValue: '8000',
        envVariableName: 'PORT',
        type: 'number'
    }
});

module.exports = config; // An instance of Map.

The above, assuming no values are read from the environment, will assign config.js a Map instance with one key port with a value of 8000.

Fields used to configure a config variable are:

fieldrequireddescription
'envVariableName'trueThe name of the environment variable to parse. Overrides the default.
'defaultValue'falseThe value used when the variable is not found in the environment. Must always be a string, as if it has come from the environment.
'required'falseDefaults to false. When true, a corresponding environment variable is required. A default will be ignored and an error thrown when the environment variable is not found.
'type'falseThe type to cast to. Defaults to 'string'.

Default types are:

  • 'string'
  • 'number'
  • 'boolean'

Additional types can be specified as parsers.

Options

configeur accepts a second parameter consisting of an options object.

parsers

configeur comes with default parsers. To add more parsers, or override existing parsers, this array can be used. For example, to add an 'integer' type:

const config = configeur(schema, {
    parsers: [
        ['integer', value => parseInt(value, 10)]
    ]
});

Keywords

FAQs

Package last updated on 03 Jan 2017

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc