New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

env-and-files

Package Overview
Dependencies
Maintainers
1
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

env-and-files

Load configuration from environmental variables and files.

latest
Source
npmnpm
Version
8.0.0
Version published
Maintainers
1
Created
Source

env-and-files

Load configuration from environmental variables and files.

According to The Twelve-Factor App, configuration should come from environmental variables. But since environmental variables can leak easily, some people use secrets for sensitive information. This module is made to support either with minimal set-up.

Install

npm install env-and-files

Or, with yarn:

$ yarn add env-and-files

Usage

const {loadConfig} = require('env-and-files');

loadConfig({
  postgresPassword: {
    filePath: '/secrets/password',
  },
  postgresUrl: {
    format: (value) => new URL(value),
    variableName: 'POSTGRES_URL',
  },
  postgresUsername: {
    defaultValue: 'postgres',
    filePath: '/secrets/username',
  },
})
  .then((config) => {
    // "config" will be an object map of configuration properties.
    console.log(config);
  })
  .catch((error) => {
    // If any of the required properties cannot be loaded, the Promise will reject.
    console.error(error);
  });

API

loadConfig(configMap)

Load configuration. Returns a Promise that will resolve to the loaded configuration, or reject if the configuration was invalid.

configMap

Type: Object

An object map of configuration and where to find it. By default, all configuration properties are required. See usage for examples of config maps.

loadConfigSync(configMap)

Load configuration, synchronously. Returns the loaded configuration, or throws if the configuration was invalid.

configMap

Type: Object

Same as the asynchronous version.

License

MIT © Matthew Fernando Garcia

Keywords

config

FAQs

Package last updated on 01 Jun 2022

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