npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

env-universal

v0.4.0

Published

Standard environment utils and constants for browser and node JavaScript applications

Downloads

20

Readme

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:

Env | Condition | Notes | ------------ | -----------|----------| development| NODE_ENV is undefined or 'development' | Should only be true in local development environments | production | APP_ENV is 'production' | NODE_ENV should be 'production' for deployments | staging | APP_ENV is 'staging' | NODE_ENV should be 'production' for deployments | preprod | APP_ENV is 'preprod' | NODE_ENV should be 'production' for deployments | qa | APP_ENV is 'qa' | NODE_ENV should be 'production' for deployments | test | NODE_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.

Runtime | Condition | ------------ | -----------| server | SERVER has any value | client | CLIENT 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

Target | Behavior ------------ | ------------- npm test | Runs tests in browser and node runtimes npm run tdd | Runs tests, bundles and re-runs on file changes npm run test:coverage | Runs tests and outputs a code coverage report to /coverage npm run test:ci | Runs tests, outputs code coverage npm run lint | (Run as a git pre-commit hook) Runs eslint npm run docs | Generates 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 | minor | major | prepatch | preminor | premajor | prerelease, or a valid semver version: 1.2.3.

npm run will list all npm scripts