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 🙏

© 2026 – Pkg Stats / Ryan Hefner

environmentize

v0.1.7

Published

Utilities for handling differences between environments.

Downloads

13

Readme

environmentize (e12e)

Utilities for handling value and behavior differences between environments.

Build Status NPM version Dependency Status Coverage Status Code Climate

environmentize helps you to set different values for each environment your code runs in. For example, you probably have different database settings for each environment or you probably want to use an analytics code only in production. environmentize helps you getting it done:

config.DB_HOST = e12e({
  production : '123.456.789.3',
  staging : '123.456.789.4'
}, '127.0.0.1');

config.ANALYTICS_ID = e12e.production('X-12345-6', null);

Or maybe there's some code you want to run only while in development:

e12e.development(function () {
  // This will run only if you are in development.
  console.log('This is the development environment.');
});

Installation

Install from NPM:

npm install environmentize

Usage

Require it:

var e12e = require('environmentize');

Get the current environment:

e12e(); // 'development'
// or
e12e.env; // 'development'

environmentize will use the NODE_ENV environment variable to get the environment in which the code is running. You shouldn't ever need to change e12e.env yourself.

By default, environmentize sets five environments: 'development', 'test', 'integration', 'staging' and 'production'. If you have a different environment structure, you can change them using e12e.setup().

NOTE: The following examples assume we are in the 'development' environment, unless stated otherwise.

Check if the code is being run in a given environment:

e12e('development'); // true
e12e('integration'); // false

// You may use an array of environments as well
e12e(['test', 'development']); // true
e12e(['staging', 'production']); // false

Get a value from an environment-value map:

e12e({
  development : 'foo',
  production : 'bar'
}); // 'foo'

e12e({
  integration : 'foo',
  production : 'bar'
}); // undefined

// You can set a fallback value
e12e({
  integration : 'foo',
  production : 'bar'
}, 'baz'); // 'baz'

Get a value for a specific environment:

e12e('development', 'foo'); // 'foo'
e12e('integration', 'foo'); // undefined

// With a fallback
e12e('integration', 'foo', 'bar'); // 'bar'

// This works with multiple environments too
e12e(['test', 'development'], 'foo'); // 'foo'
e12e(['staging', 'production'], 'foo'); // undefined
e12e(['staging', 'production'], 'foo', 'bar'); // 'bar'

Values may be functions, in which case they are called without arguments and the returned value is used:

e12e('development', function () { return 'foo'; }); // 'foo'

// Works for fallbacks too
e12e('integration', function () { return 'foo'; }, function () { return 'bar'; }); // 'bar'

// And for values in an environment-value map
e12e({
  development : function () { return 'foo'; }
}); // 'foo'

This way you can run a piece of code only in certain environments:

e12e('development', function () {
  // Do something that should only be done during development.
  console.log('This is the development environment');
});

Environmentize also sets a method for each environment, which avoids the need for the first argument in some cases:

e12e.development('foo'); // 'foo'
e12e.integration('foo', 'bar'); // 'bar'

This might be handy if you need to run some code only in a specific environment:

e12e.production(function () {
  // This code will run only in production.
  app.use(toobusy());
});

Configuration

You can use your own environment definitions using e12e.setup():

e12e.setup({
  environments : ['dev', 'ci', 'stg', 'prod'],
  defaultEnv : 'dev'
});

e12e.dev('foo'); // 'foo'
e12e.ci('foo', 'bar'); // 'bar'

// Original environment methods are removed
e12e.development('foo'); // throws error

Testing

Environmentize's tests are written in mocha and can be run with:

npm test

Contributing

Feel free to submit any patches or report any issues. I'll do my best to check them as quick as possible (in a few days, usually). When submitting a patch, please add your name and link to the author section below.

I would greatly appreciate if someone could double check the tests. I'm sure there's plenty of room for improvements there.

Issues and patches regarding grammar errors in code comments and docs are welcome as well. : )

Author

Created by Mathias Kretschek (mkretschek).