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

@ig3/config

v0.2.2

Published

This packages loads configuration from command line, environment and a set of configuration files.

Downloads

4

Readme

@ig3/config

This packages loads configuration from command line, environment and a set of configuration files.

Install

$ npm install @ig3/config

Usage

const config = require('@ig3/config')();
console.log("config: ", JSON.stringify(config, null, 2));

The package exports a single function that takes an options argument and returns a configuration object.

Configuration is read from defaults, one or more configuration files, environment variables beginning with the name of the program and command line arguments. The same parameter may appear more than once in which case the later appearance overrides previous appearances.

Configuration

Options may be passed to the factory:

const options = {};
const config = require('@ig3/config')(options);

debug (false)

If truthy, print debug messages to console.debug.

options.debug = true;

defaults ({})

Default configuration parameters.

options.defaults = {
  option1: 'value1',
  option2: 'value2',
  option3: true,
  option4: 1234
};

argv (minimist)

Parsed arguments from process.argv, or wherever you like.

If not set, minimist is used to parse the arguments.

  require('minimist')(process.argv.slice(2), {
    string: ['config'],
    boolean: ['debug'],
    alias: {
      config: ['C'],
      debug: ['d']
    }
  });

For example, to use nopt to process command line arguments:

options.argv = nopt(knownOpts, shortHands, process.argv, 2);

name (path.basename(process.argv[1], '.js'))

The name of the program.

options.name = 'myapp';

config (undefined)

The path of a config file to load. This file, if it exists, overrides all other config files from opts.paths.

options.config = '/tmp/test/config.json';

paths

The paths to search for config files.

Default paths are:

  • /etc/<name>
  • /etc/<name>/config
  • /usr/local/etc/<name>
  • /usr/local/etc/<name>/config
  • ~/.config/<name>
  • ~/.config/<name>/config
  • ~/.<name>
  • ~/.<name>/config
  • .<name>
  • <name>

The path starting with '~' are dependent on the environment variable HOME being set. If it is not set, these paths will not be checked.

options.paths = [
  '/etc/myapp.json',
  path.join(process.env.HOME, '.myapp.json'),
  '.myapp.json'
];

The order of paths is significant. If multiple files are found their contents are merged. If the same parameter appears in more than one file, the value from files later in the list will override values from files earlier in the list. in the list of paths will override those earlier in the list.

parsers The config file parsers.

Parsers for config files are selected by filename extension. If there is no extension, the parser for the last extension in option extensions is used.

options.parsers = {
  '.json5': JSON5.parse,
  '.json': JSON.parse,
  '.ini': ini.parse
};

extensions

An array of extensions to try if a path does not end with an extension.

options.extensions = [
  '.ini',
  '.xml',
  '.json'
];

### Methods

None.

## License

MIT, see [LICENSE.md](http://github.com/ig3/agiloft-script/blob/master/LICENSE.md) for details.

## Change Log

### 0.2.2 - 20220331

Update all dependencies.

### 0.2.1 - 20220331

Fix the precedence of config option: command line; environment; options

### 0.2.0
Remove strop-json-comments and add JSON5.

### 0.1.0
Add missing dependencies

### 0.0.1

Initial release