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

environment-override

v1.0.3

Published

Takes a JSON object and checks the environment variables for overrides to its values. Great for HAPIjs manifests and other configuration.

Downloads

929

Readme

Environment Override

view on npm npm module downloads per month Dependency status Travis status Code coverage License

Takes an object holding configuration and checks the environment variables for overrides to its values. Great for hapi manifests and other types of configuration.

How to use

The code is currently synchronous as its expected to only be run once as part of the startup of the app.

In code

var override = require('environment-override').override;
var manifest = require('./manifest.json');
override(manifest, 'PREFIX_');

Command line

environment-override ships with an utility that can show you all the variables from a json file that can be overridden via environment variables:

node ./node_modules/environment-override/bin/show test.json

To avoid polluting the environment you can set a prefix for the variables:

node ./node_modules/environment-override/bin/show test.json -p PREFIX_

It can also show the original and overridden versions:

node ./node_modules/environment-override/bin/show test.json -o diff

The output can be:

  • diff - Shows the diff between the two versions.
  • all - Shows both the original and the overridden versions.
  • original - Shows the original version.
  • current - Shows the overridden version.

Removing values

To remove a value set the entry to OVERRIDE_REMOVE_DATA in the environment.

Whole structures

To override whole structures use a stringified JSON object in the variable:

exports PREFIX_VARIABLE='{"key1": "value1", "key2": "value2"}'

Example

Assuming we have the following test.json file:

{
  "field1": "value1",
  "field2": {
    "s1": "v1",
    "s2": "v2"
  },
  "field3": "value3"
}

We can see all the variables by running show.js:

./bin/show.js test.json -p APP_                              
INFO: Using the prefix "APP_" you have the following overrides:
		APP_FIELD1
    APP_FIELD2
    APP_FIELD2_S1
    APP_FIELD2_S2
    APP_FIELD3

We can override them by setting various values:

export APP_FIELD1 = 'updated1'
export APP_FIELD2 = '{"s1": "updated_f2_value1", "s2": "updated_f2_value2"}';
export APP_FIELD3 = 'OVERRIDE_REMOVE_DATA'

Running show.js again will inform us of which variables were overridden:

./bin/show.js test.json -p APP_                                      
INFO: Using the prefix "APP_" you have the following overrides:
  overridden APP_FIELD1
  overridden APP_FIELD2
     removed APP_FIELD3	     

We can also get a diff:

./bin/show.js test.json -p APP_ -o diff