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-lift

v0.0.3

Published

Simple namespaced environment variable configuration management solution

Downloads

18,109

Readme

env-lift

env-lift provides a NodeJS module to easily read configurations from environment variables. The module makes it super easy to abstract configuration loading from environment in an organised and namespaced manner.

Installing env-lift

The easiest way to install env-lift is from the NPM registry. Switch to your project directory and run the following command. Once installation completes, refer to the usage guidelines or the examples directory to use it in your project.

npm install env-lift --save

Usage

The best way to understand how to use this module is to refer to examples. A couple of them is located within the /examples directory and here we would elaborate on a few use cases.

A simple use case where config is stored in an external JSON file

In this use-case, let us assume that you are storing your config in a simple javascript variable. For your production server, you are possibly modifying the variables and running your application. In reality, the use-case could be that you are fetching the configuration from a separate JSON file. But for all practical purposes, the example here could be morphed to meet those scenarios.

Original Code:

var config = {
    port: 80,
    environment: 'development',
    db: {
        host: 'localhost',
        user: 'root',
        password: ''
    }
};

Updated code using env-lift:

var config = require('env-lift').load('my-app', {
    port: 80,
    environment: 'development',
    db: {
        host: 'localhost',
        user: 'root',
        password: ''
    }
});

At this stage, if you can override the values of the configuration using environment variables.

export MY_APP_PORT=8080;
export MY_APP_DB_HOST="example.com";

Executing the above terminal exports before running your app would return port as 8080 and also return db host as example.com.

Some gotchas

  • The keys are expected to be all uppercase alphanumeric.
  • The first letter of the environment variable cannot be a number.
  • If your key has non-alphanumeric characters, they are replaced by underscore character

Contributing

Contribution is accepted in form of Pull Requests that passes Travis CI tests. You should install this repository using npm install -d and run npm test locally before sending Pull Request.