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

yaml-conf

v1.0.2

Published

Simple yaml-based configuration utility

Downloads

8

Readme

yaml-conf

A simple yaml-based configuration utility for node apps, kept intentionally feature-light in order to make the configuration files less intimidating to non-technical users.

Basic Usage

Assuming the following files exist:

In /path/to/project/package.json:

{
	"name": "application-name",
	...
}

In /path/to/project/default.conf.yml:

foo: default foo
bar: default bar

In ~/application-name.conf.yml

foo: conf foo
baz: conf baz

You can create a configuration object using the build method:

const yamlConf = require('yaml-conf');

let conf = yamlConf.build();

console.log(conf);
// {
//     foo: 'conf foo',
//     bar: 'default bar',
//     baz: 'conf baz'
// }

Options

The build method allows you to provide options:

let conf = yamlConf.build({
	projectDir: 'custom/project/dir',
	appName: 'custom-app-name',
	path: 'path/to/config/file',
	overrides: { foo: 'override foo' }
});
  • projectDir: Normally, build obtains the project directory by traversing directories upward from require.main.filename, checking each directory for the existence of package.json as it goes. If this won't work in your project structure, or you want to specify a different project directory for whatever reason, you can do it here. If so, it must be a full path.
  • appName: Normally, build obtains the app name from package.jsonin the project directory. If this won't work in your project, or you'd like to provide a different name for whatever reason, you can do it here.
  • path: As demonstrated above, build defaults to reading from a file in the user's home directory with the name ${appName}.conf.yml. You may use this option to specify an alternate configuration file. This supports both absolute paths as well as paths relative to the current working directory.
  • overrides: Properties set here will override properties from files in the result object. Use this to allow configuration through command-line arguments or other non-yaml means.

Example

yaml-conf fits well into the following pattern using commander and lodash:

const _ = require('lodash');
const program = require('commander');
const yamlConf = require('yaml-conf');
const pkg = require('./package.json');

program
	.version(pkg.version)
	.description(pkg.description)
	.option('-c --config', 'Path to custom configuration file')
	.option('-f --foo', 'foo option')
	.option('-b --bar', 'bar option')
	.parse(process.argv);

let conf = yamlConf.build({
	path: program.config,
	overrides: _.pick(program, [ 'foo', 'bar' ]);
});

Similar Projects

As noted above, yaml-conf is kept intentionally feature-light. If you need more features, you may be intersted in the following modules: