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

env-universal

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

env-universal

Standard environment utils and constants for browser and node JavaScript applications

  • 0.4.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
5
Maintainers
1
Weekly downloads
 
Created
Source

env-universal

Build Status Libraries.io for GitHub Coverage Status NPM version NPM downloads MIT License

Sauce Test Status

Standard environment definition, utilities and constants for browser and node JavaScript applications

Introduction

This package provides utilities for working with environment configuration consistently in different runtimes via configuration objects or environment variables.

We created this at WeWork to provide our applications a more consistent runtime. We use it with tools like dotenv and webpack in universal JavaScript applications.

Environment configuration

We use a matrix of variables to define the environment of our applications:

EnvConditionNotes
developmentNODE_ENV is undefined or 'development'Should only be true in local development environments
productionAPP_ENV is 'production'NODE_ENV should be 'production' for deployments
stagingAPP_ENV is 'staging'NODE_ENV should be 'production' for deployments
preprodAPP_ENV is 'preprod'NODE_ENV should be 'production' for deployments
qaAPP_ENV is 'qa'NODE_ENV should be 'production' for deployments
testNODE_ENV is 'test' or 'testCI'

Note that NODE_ENV=production only indicates that the app is deployed (vs running locally in development) and that APP_ENV specifies the environment.

RuntimeCondition
serverSERVER has any value
clientCLIENT has any value

By default, config is read from environment variables (process.env), but you can also pass in your own configuration object.

Usage

See the documentation. Note that most util functions expect to receive process.env when not calling the root env function.

This package is bundled as a CommonJS module in dist and can be required like any other. The ES2015 source is also exposed via the jsnext:main field in the package.json for loaders that support module syntax directly.

Webpack

utils.getPublicEnv is very handy to safely expose environment config for a client bundle. See docs for getPublicEnv, and our own use of it in test/browser/webpack.config.js.

Examples

import getEnv from 'env-universal';
const env = getEnv();

console.log(env.version);
console.log(env.is.client);
console.log(env.is.server);
console.log(env.is.deployed);
console.log(env.is.production);
console.log(env.is.dev);

Development

  1. Checkout this repo
  2. Run npm install
  3. Make changes in a feature branch and open a PR to master

In lieu of a formal style guide, please:

  • follow the conventions present in the codebase
  • respect the linter
  • keep tests green
  • maintain test coverage

npm scripts

npm scripts

TargetBehavior
npm testRuns tests in browser and node runtimes
npm run tddRuns tests, bundles and re-runs on file changes
npm run test:coverageRuns tests and outputs a code coverage report to /coverage
npm run test:ciRuns tests, outputs code coverage
npm run lint(Run as a git pre-commit hook) Runs eslint
npm run docsGenerates API.md from JSDoc comments in /src
npm run security-scan(Run as a git pre-push hook) Checks npm dependencies for security vulnerabilities
npm run release <version>Generates a changelog, updates package version, tags and pushes via np. This should only be run on an up-to-date master by a maintainer of this package.

Version can be a semver level: `patch

npm run will list all npm scripts

Keywords

FAQs

Package last updated on 24 Jul 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