npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

conf-fu

v0.5.19

Published

Advanced configuration with includes, variables and placeholders.

Downloads

11

Readme

conf-fu

build NPM Version codecov.io

Simple configuration module to handle complex problems

Install

npm install -g conf-fu

Synopsis


var ConfFu = require ('conf-fu');

// init from files
var config = new ConfFu ({
   configFile: path.join (configDir, 'index.json'),
   fixupFile:  path.join (configDir, 'fixup.json')
});

config.verbose = globalVerbose || false;

config.on ('ready', function () {
   done();
});

config.on ('error', function (eOrigin, eType, eData, eFile) {
   assert (false, 'wrong config');
});

// init from structures
var config = new ConfFu ({
   config: {a: {b: {c: "<#who knows>"}}, x: true}
});

Goals

  1. Easy to use

    Common formats, you can set up a location of configuration files. If you already have one, you do not need to change files location for each project, you can just point this location (set up environment) for all needed projects.

  2. Scalable

    Hierarchical, any section can live in a separate file, easy access to frequently changing sections.

  3. Easy deployment

    Configuration is actually is splitted to the project configuration and the instance fixup. You can have as many fixups as you want, not only development and production.

  4. Persistent

    Current configuration snapshot is always on disk and in vcs. No code allowed within configuration. Tools never change project config, only fixup allowed to change.

Those is not acceptable:

  1. require ('config.json') — 1, 2, 3;
  2. nconf - 4 (require code to load includes)
  3. node-convict - 2 (no access to frequently changing sections), 3 (no separation beween project config and instance fixup)
  4. dotenv - 2, 4 (recommended not to commit config)
  5. node-config - 1 (cannot change location), 4 (instance name not stored on disk)

Configuration file

Configuration format when parsed must be presented with tree or key-value structure.

Each string can be basic or enchanted. conf-fu supports those enchantments:

  1. variables

    examples:

    • <$db.mongo.collection> — linked to the other value in configuration
    • <$bool(on|off):db_unix_sock=on> — variable with type and default value
    • <$http_domain>:<$http_port> — string concatenation
  2. placeholders

    examples:

    • <#placeholder> — just a placeholder, need to be fullfilled
    • <#optional:placeholder> — you can omit this value in fixup
    • <#default:127.0.0.1> — you can omit this value in fixup and default value will be used
  3. includes

    examples:

    • <<filename>> — parsed content from filename need to be inserted into that node

Usage

You can use conf-fu standalone, integrate within project or use it in browser.

####node.js in standalone mode

conf-fu configuration is located within .conf-fu directory in project root. Main configuration file named project.json, fixup directories located at same level as the project.json file.

  1. project.json file is loaded and parsed. json, ini and yaml formats supported, new formats can be added easily;
  2. project.json contents is scanned for includes in form "<include-file-name>";
  3. when all includes is loaded, config tree is scanned for variables ("<$config.path.variable>") and placeholders ("<#please fix me>", "<#optional:please fix me>", "<#default:127.0.0.1>");
  4. fixup.json file loaded and checked, whether all variables and placeholders fulfilled;
  5. if resulting config is fulfilled, conf-fu emits ready event; otherwise, error event emitted.

#####Environment variables to drive config

required:

  • CONF_FU core file path, parent directory is assumed as config location
  • CONF_FU_FIXUP fixup file path
  • INSTANCE or CONF_FU_INSTANCE instance name

optional:

  • CONF_FU_PROJECT (relative to project root, dir name to search for project.json file)

Integration to the existing project

You have two options to integrate conf-fu to existing projects:

  1. Use as configuration management script

    For example, one part of your project written on php and you want to add conf-fu. You'll need to install conf-fu from npm, then just use it from command line to edit configuration, validate it, fullfill variables and placeholders. Then, just ask conf-fu to store configuration artifact in place where you can read it with php.

  2. Use within code to get a configuration.

TODO

Links

  • http://thejeffchao.com/blog/2013/09/26/an-alternative-node-dot-js-configuration-management-pattern/
  • http://metaduck.com/03-konphyg.html
  • https://github.com/mozilla/node-convict
  • https://github.com/scottmotte/dotenv