Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

nenv

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nenv

Utility for managing node development environments

  • 0.2.5
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3
decreased by-50%
Maintainers
1
Weekly downloads
 
Created
Source

Table of Contents

  • nenv

nenv

Utility for mananging node development environments.

Requires node and npm.

Install

npm i nenv --save

Usage

function nenv([environments, get, set])
var env = require('nenv')();
if(!env.defined) {
  // do something when no environment was specified
  // maybe: env.set(env.DEVEL) or whichever default you want
}else if(!env()) {
  // do something when the specified environment is invalid
}else if(env.test) {
  // do something for test environment
}
  • environments: Array or object of custom environments, if not specified the defaults are used.
  • get: A custom function for getting the environment value (optional).
  • set: A custom function for setting the environment value (optional).

env([value])

Determines if an environment value is valid. Returns false is the supplied value is invalid or the string key for the environment if valid.

If no value is supplied then env.value is used which allows testing whether the default value is valid by calling with no arguments.

env.value

The value returned from get() when nenv() was called, the initial environment value.

env.valid

Boolean that determines whether env.value is a recognised environment.

env.defined

Determines whether an initial value (env.value) was defined.

env.get()

Get the current value of the environment, the default implementation returns process.env.NODE_ENV.

env.set(val)

Set the current value of the environment, the default implementation returns false if the supplied value is not a known environment alias otherwise a function that may be called to revert to the previous value.

env.defaults

Default values to use.

['test', 'devel', 'stage', 'production'];

Environments

Pass an object or array to define your available environments:

var nenv = require('nenv')
  , env = nenv({production: ['production', 'pro'], dev: 'dev', test: 'test'});
console.log(env.keys);

Example

var env = require('./')()
  , str = JSON.stringify(env.jsonify(), undefined, 2);
process.stdout.write(str);

Executed with NODE_ENV=devel, yields:

{
  "TEST": "test",
  "DEVEL": "devel",
  "STAGE": "stage",
  "PRODUCTION": "production",
  "value": "devel",
  "valid": true,
  "defined": true,
  "map": {
    "test": [
      "test"
    ],
    "devel": [
      "devel"
    ],
    "stage": [
      "stage"
    ],
    "production": [
      "production"
    ]
  },
  "keys": [
    "test",
    "devel",
    "stage",
    "production"
  ],
  "test": false,
  "devel": true,
  "stage": false,
  "production": false
}

Developer

Test

Run the test specifications:

npm test

Readme

Generate the project readme file (requires mdp):

npm run readme

License

Everything is MIT. Read the license if you feel inclined.

Generated by mdp(1).

Keywords

FAQs

Package last updated on 14 Apr 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc