Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

eu-node-config

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eu-node-config

A simple config file loader

  • 0.0.4
  • latest
  • Source
  • npm
  • Socket score

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

EuNodeConfig

NOTE, THIS IS A WORK IN PROGRESS AND NOT COMPLETE AT THIS TIME To see what works, look at the test(s).

Node config is a simple library for loading configuration from the environment and various file formats. It allows your users to specify their configs in various formats and takes care of parsing the formats appropriately for you.

Usage

This module exports only one function: loadConfig.

var configLoader = require('eu-node-config');
configLoader.loadConfig({
  username: {
    default: "bob", // A config with a default value can't be required
  },
  username2: "anotherDefaultFormat",
  secure: {
    required: true,
    error: "Missing required config value: secure" // This default message will be printed if you do not supply your own. This can only be used if the config has a validation, such as required.
  },
  anotherConfigKey: {
    error: true
  },
  finalConfigKey: {} // This config value will not be required and might not be in the object returned
}, {
  configFolders: ['/etc/myconf'],                       // Optional, defaults to working directory and then process base directory
  filePrefix: 'part-before-the-dot',                    // Optional, defaults to config
  order: ["string", "environment", "json", "yaml", "defaults"], // Optional, defaults to the value shown left; earlier values will override later values
                                                        // other options include "js" to load from a .js file
  configString: '{"key": "value"}',                     // The 'string' source above.
}, function(err, config) {
  console.log("Config loaded: " + config);
});

// Alternately, promise style
configLoader.loadConfig({username: {default: "bob"}, {jsonData: '{"username":"bill"}'})
.then(function(config) {
  console.log(Config loaded: " + config);
})
.error(function(err) {
  console.log("Failed to load config: " + err);
});

Formats supported

.yaml, .json, and .js

From the above description, your config will be loaded from a file if it begins with your filePrefix (default config) and ends with ".json" or ".yaml". If you enable "loadJsConfigs" it will also load .js extension files.

Environment variables

Environment variables matching either your config key or your config key converted to upper-case and with camelcasing normalized to underscore seperation will be used.

For example, the config key "configKey" will be accessed as either the environment variable "configKey" or "CONFIG_KEY"

FAQs

Package last updated on 05 Nov 2015

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