Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

reloadable-env

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

reloadable-env

Ever wanted to change environment variables on the fly whenever you need?

latest
Source
npmnpm
Version
0.1.0
Version published
Maintainers
1
Created
Source

Reloadable ENV

Ever wanted to change environment variables on the fly whenever you need?

I know I have.

Installation:

Git
npm i git://github.com/Icehunter/reloadable-env -S
npmjs
npm i reloadable-env
package.json
"dependencies": {
    "reloadable-env": "git://github.com/Icehunter/reloadable-env.git"
}
Version Specific
"dependencies": {
    "reloadable-env": "git://github.com/Icehunter/reloadable-env.git#hash|branch"
}

Usage:

This library has three events as noted below.

'use strict';

function handleConfiguration(env) {
    for (var key in env) {
        process.env[key] = env[key];
    }
}

var reloadable = require('reloadable-env')('relative/path/to/env.json', {
    configured: function(env) {
        handleConfiguration(env);
    },
    reconfigured: function(env) {
        handleConfiguration(env);
    },
    error: function(err) {
        console.error(err);
    }
});

Recommendations:

It is recommend that you use async and wait for the configuration to be loaded before continuing initialization.

ENV changes are as simple as modifying the env.json file in the repository and doing a git pull.

Example:

Run this with 'npm i && node example/async.js'

'use strict';

var async = require('async');
var path = require('path');

async.series([

    function (cb) {
        console.log('Initial ENV:');
        console.log(process.env);

        function handleConfiguration(env) {
            for (var key in env) {
                process.env[key] = env[key];
            }
            console.log(process.env);
        }

        require('../lib/reloadable-env')({
            configPath: path.join(__dirname, './env.json')
        }, {
            configured: function (env) {
                console.log('Configured ENV:');
                handleConfiguration(env);
                cb();
            },
            reconfigured: function (env) {
                console.log('Reconfigured ENV:');
                handleConfiguration(env);
            },
            error: function (err) {
                console.error(err);
            }
        });

    },
    function (cb) {
        console.log('Do Some More Stuff');
        cb();
    }
], function (err) {
    if (err) {
        console.error(err.message || err);
    }
    else {
        console.log('Initalization Complete');
    }
});

Keywords

reloadable

FAQs

Package last updated on 12 Aug 2014

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