Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including parse-env with all npm packages installed. Try it out:

var parseEnv = require("parse-env")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

parse-env v0.5.0

Parses configuration from env

build status

parse-env - Parses configuration from env

parse-env makes it easy to make your project support environment variable based configuration. It infers the environment variable names based on the given template. That template may be the configuration itself. Should an environment variable matching to the convention be found, it will use that rather than the one in the original configuration.

To make the way it works clearer, consider the example below. It consists of three files. The first one is a template which you would store at your repository. The second one is a private configuration not stored for security reasons. The third one deals with parsing. The files are inside a config package. The last file works as an entry point to it.


module.exports = {
    port: 8000,
    aws: {
        accessKeyId: 'replacethis',
        secretAccessKey: 'replacethis'


module.exports = {
    port: 80,
    aws: {
        accessKeyId: 'actualid',
        secretAccessKey: 'actualkey'


var parseEnv = require('parse-env');

var tpl = require('./config.template');

// the configuration file is optional and doesn't have to exist
var conf;

try {
    conf = require('./config');
catch(e) {}

module.exports = parseEnv(process.env, tpl, conf);

The parser is convention based. It performs the following conversions:

  • parseJSON -> PARSE_JSON
  • port -> PORT
  • aws.accessKeyId -> AWS_ACCESS_KEY_ID
  • -> FOO_BAR_BAZ_GAZ (recursive definition)

In case no match is found either in the environment or configuration, it will just skip the value. If you want to enable warnings, set VERBOSE_PARSE_ENV as a truish value.


parse-env is available under MIT. See LICENSE for more details.

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free