Giter VIP home page Giter VIP logo

node-config's Introduction

node-config

Get and set config values

Examples

const Config = require('@nicklason/config');

const config = new Config({
    directory: './', // Use current working directory
    filename: 'config.json', // The config will be named config.json
    timeout: 0 // The config will be saved right as it changes in memory
});

config.init(function (err) {
    if (err) {
        throw err;
    }

    // Adds foo to the config with the value bar, returns previous value
    console.log(config.set('foo', 'bar'));
    // -> undefined

    console.log(config.get('foo'));
    // -> bar

    // Removes the key from the config, returns the value of it
    console.log(config.del('foo'));
    // -> bar


    // bar is undefined, foo is the default value
    console.log(config.get('bar', 'foo'));
    // -> foo

    // Clears the config
    config.data = {};
});

// Wait some time before exiting
setTimeout(function () {
    // Gracefully close the config
    config.exit(function (err) {
        // Config is now saved, you can safely close the script (if no error)
    });
}, 1000);

Watch for changes by other processes.

const Config = require('../');

const config = new Config({
    directory: './',
    filename: 'config.json',
    watch: true // Watch the data directory for changes to the config by other processes
});

config.on('change', function (oldData, newData) {
    console.log('Config was modified by a different process');
});

node-config's People

Contributors

nicklason avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.