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

envz

v1.0.1

Published

A dead simple module for storing and managing your environment variables in a simple and easy to read yaml file.

Downloads

2

Readme

envz

envz is a dead simple module for storing and managing your environment variables in a simple and easy to read yaml file.

# with npm
npm install envz

# or with Yarn
yarn add envz

Usage

You should use envz as early on in the entry point of your app as possible. Eg: app.js or index.js file which loads your app.

Rather than override process.env.x object, envz will return a new object to use throughout your app.

const { envz } = require('envz');

Create a env.yaml or any other named file and load it:

const env = envz('env.yaml');

env YAML file structure

The idea is that the process.env will be merged with loaded yaml file.

env uses a cascading (sequential order) configuration method which is easier to understand looking at an example.

base:
  PORT: 1234
  config:
    default: test

development:
  PORT: 3000
  DATABASE: dev
  config:
    token: 12345
    secret: fwdsdgl

production:
  PORT: 80
  DATABASE: prod
  config:
    token: 67890
    key: puwndklf
    truthy: true
    allowed:
      - card
      - phone

The idea here is that the values in base are loaded, anything in development overrides that and finally production overrides that depending on the NODE_ENV set.

For example, when a NODE_ENV of development is set the following env object is returned:

PORT: 3000,
config: { 
    default: 'test', 
    token: 12345, 
    secret: 'fwdsdgl' 
},
DATABASE: 'dev'
...

Eg: Where the PORT of 3000 from development overrides the base setting of 1234. If the NODE_ENV is set to production, then the PORT will be set to 80.

The idea behind base (or whatever you want to call it) is that you don't need to redefine defaults over and over for each environment.

Options

You can set the environment manually rather than using NODE_ENV by adding an environment object. Eg:

const env = envz('env.yaml', { environment: 'production' });

By default the values set in process.env overrides what is set in your yaml file. You can change this so that the yaml file is king by adding the following flag:

const env = envz('env.yaml', { yamlFileOverride: true });

Save / Update config

Sometimes you may want to store changes back to your envz config. You can easily do this by importing save:

const { save } = require('envz');

The save method takes an object with two values:

  • envfile: The yaml file you are wanting to update
  • data: The object you want to update back to the file. See tests and example below.
// In this case we will be adding to the `base` config but you can easily
// replace `base` with `production` or whatever environment.
const saveObj = await save({
    envfile: 'test.yaml',
    data: {
      base: {
        config: {
            default: 'default-key'
        }
      }
    }
});

This will result in the test.yaml being updated:

base:
  PORT: 1234
  config:
    default: default-key
...