New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

config-store

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

config-store

A JavaScript config store

  • 0.3.1
  • latest
  • Source
  • npm
  • Socket score

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

Config Store

A JavaScript config store.

The source is available for download from GitHub. Alternatively, you can install using Node Package Manager (npm):

npm install config-store

On the Server

On the server, it will read from three different locations (in order of priority):

  • command line arguments
  • a JSON configuration object (which may be read from a file)
  • environment variables

Usage:

var configStore = require('config-store');
var config = configStore({...});
// or      = configStore('./config.json');

var port = config('PORT', 3000);
var host = config('HOST');

Alternatively:

var configStore = require('config-store');
configStore({...}, function (err, config) {
  var port = config('PORT', 3000);
  var host = config('HOST');
});

In the Browser

In the browser, it will read from a JSON configuration object (which may be read from a file). So far it's not been tested - feel free to do so!

Usage:

<script src="configStore.js"></script>

<script>
  (function () {
    var config = configStore({...});

    var port = config('PORT', 3000);
    var host = config('HOST');
  })();
</script>

<script>
  (function () {
    configStore('/config.json', function (err, config) {
      var port = config('PORT', 3000);
      var host = config('HOST');
    });
  })();
</script>

find

Sometimes, you might want to pull in entire sets of data from config...

{
  "db": {
    "host": "...",
    "user": "...",
    "password": "..."
  }
}

The standard config lookup doesn't handle this, as it maps this type of structure to env-style variables, so config('db') would not return anything.

However, config.find is available for this type of situation, and lets you pull blocks of config out of the store. Unlike the standard lookup, it won't throw an error if the key is not found and you don't provide a fallback - the return value will just be undefined.

var db = config.find('db');
// {host: "...", user: "...", password: "..."}
var user = config.find('db.user');
// "..."
var port = config.find('db.port');
// undefined
var port = config.find('db.port', 80);
// 80

FAQs

Package last updated on 03 Jan 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

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