env-cache

0.1.0 • Public • Published

env-cache NPM version NPM monthly downloads NPM total downloads Linux Build Status

Get and set values on process.env using a namespace.

Follow this project's author, Jon Schlinkert, for updates on this project and others.

Install

Install with npm:

$ npm install --save env-cache

Why use this?

This library makes it easier to get and set values on process.env. Anywhere you need to access the process.env values, just create a new instance with the namespace you want to access.

Usage

var EnvCache = require('env-cache');
 
// the given namespace is automatically uppercased
var env = new EnvCache('your-namespace');
 
env.set('production', true);
console.log(env.get('production'));
//=> 'true'

API

EnvCache

Create an instance of EnvCache with the given namespace. The namespace is automatically uppercased and is then used by the .set and .get methods to prefix keys.

Params

  • namespace {String}: The namespace to use on process.env.

Example

var env = new EnvCache('foo');

.set

Set a value on your process.env namespace.

Params

  • key {String}
  • val {any}

Example

env.set('dev', true);
console.log(process.env.FOO_DEV);
//=> true

.get

Get a value from your process.env namespace.

Params

  • key {String}

Example

env.set('dev', true);
console.log(env.get('dev'));
//=> true

.enabled

Returns the true boolean if the value of key is the string "true".

Params

  • key {String}

Example

env.set('dev', true);
console.log(env.enabled('dev'));
//=> true

.disabled

Returns the false boolean if the value of key is the string "false".

Params

  • key {String}

Example

env.set('dev', true);
console.log(env.disabled('dev'));
//=> false
 
env.set('dev', false);
console.log(env.disabled('dev'));
//=> true

About

Related projects

You might also be interested in these projects:

  • base: Framework for rapidly creating high quality node.js applications, using plugins like building blocks | homepage
  • cache-base: Basic object cache with get, set, del, and has methods for node.js/javascript projects. | homepage
  • data-store: Easily get, set and persist config data. | homepage

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.

Building docs

(This project's readme.md is generated by verb, please don't edit the readme directly. Any changes to the readme must be made in the .verb.md readme template.)

To generate the readme, run the following command:

$ npm install -g verbose/verb#dev verb-generate-readme && verb

Running tests

Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:

$ npm install && npm test

Author

Jon Schlinkert

License

Copyright © 2017, Jon Schlinkert. Released under the MIT License.


This file was generated by verb-generate-readme, v0.6.0, on August 27, 2017.

Readme

Keywords

Package Sidebar

Install

npm i env-cache

Weekly Downloads

2

Version

0.1.0

License

MIT

Last publish

Collaborators

  • jonschlinkert