Socket
Socket
Sign inDemoInstall

@4c/env

Package Overview
Dependencies
5
Maintainers
3
Versions
10
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @4c/env

Environment variable management and helpers


Version published
Weekly downloads
387
increased by17.63%
Maintainers
3
Install size
791 kB
Created
Weekly downloads
 

Readme

Source

@4c/env

A small set of utils for working with environment variables in node and webpack projects. Wraps the excellent getEnv as well

Usage

import * as Env from '@4c/env';

Getting and parsing variables

env wraps and reexports getEnv as get().

Env.get('NODE_ENV'); // 'production'

// Fails hard on missing variables
Env.get('NOT_SET_VAR'); // Error

// Fall back to a default if needed
Env.get('NOT_SET_VAR', 'default_value'); // 'default_value'

// Parsing
Env.get.int('MAX_SUBSCRIPTIONS', 4);

process.env.BOOLISH = 1;
Env.get.boolish('BOOLISH'); // true

Loading .env files

env will load and parse .env files, by environment. We use the naming convention variables-{ENV}.env to split out variables by different environment. The default is dev.

Env.load(); // adds variables-dev.env to process.env
Env.load('test'); // adds variables-test.env to process.env

There is also a utility for passing enviroment variables to webpack's DefinePlugin allowing instances of process.env.FOO in front-end code to be replaced with a specific compile-time value.

// returns variables-test.env mapped to an object keyed by process.env.[foo] for use in webpack
new webpack.DefinePlugin(Env.define('test'));

FAQs

Last updated on 08 Mar 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