Socket
Socket
Sign inDemoInstall

envboss

Package Overview
Dependencies
0
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    envboss

package for environment variables


Version published
Maintainers
1
Install size
17.8 kB
Created

Readme

Source

Known Vulnerabilities Build Status Coverage Status GitHub npm (scoped)

EnvBoss

Tired of using process.env everywhere in the code?
Tired of guessing which environment variable are mandatory and which are optional?
Tired of validating environment params?

meet EnvBoss!!!

This package will help you organize and validate all your environment variables in one place.

How does it work?

It goes over the configuration you provide, and returns an object where the key is the <ENV_PARAM_NAME> and the value is process.env[<ENV_PARAM_NAME>] after it was validated and sanitized.

configuration

mandatory - sets this param as mandatory.

default - lets you define a default value.

validationFunction - will help you validate the values.

validValues- lets you describe what values are valid.

wrappingFunction - converts the envparam value to the given value. By default, if default value is provided, process.env[<ENV_PARAM_NAME>] value will be converted to the type default's value type

If you wouldn't like to validate envparams(e.g. in tests) pass pass false to createEnvObject(ENV_VARS_CONFIG,false)

Installation

> npm i envboss

How to use

/// envVariablesConfig.js

import { createEnvObject, mandatory } from 'envboss';

const ENV_VARS_CONFIG = {
    CLUSTER: { mandatory },
    ENVIRONMENT: { mandatory, validValues: ['live', 'sandbox']},
    STORAGE_PORT: { mandatory, wrappingFunction: Number },
    IS_MASTER: { mandatory },
    // optional
    PORT: { default: 8082 },
    PROCESSOR_TIMEOUT: { default: 50000},
    RETRY_TIMES: { default: 10, validationFunction: (v) => v > 3},
    LOG_LEVEL: { default: 'info' }
};

module.exports = createEnvObject(ENV_VARS_CONFIG);
/// someFile.js
const { ENVIRONMENT } = require('envVariavbesConfig.js');

Keywords

FAQs

Last updated on 31 Oct 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