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

yamlconf

v0.0.3

Published

An alternative approach to the application configuration, with yaml and .env.

Downloads

3

Readme

yamlconf

Build Status Coverage Status

An alternative approach to the application configuration, with yaml and env variables.

Getting started

To start using this, simply require yamlconf function and call it:

const config = require('yamlconf')();

It will load configuration defined in ./config.yml file.

Also, it will look for ./config.local.yml file and if it's found, it will merge values with normal config, local values taking precedence.

Configuration

Pass the path to the config file as a string:

const config = require('yamlconf')('./path/to/config.yml');

Pass the configuration object for more options:

| Property | Meaning | Defaults to | | ---- | ---- | --- | | path | filepath to config | ./config.yml | | loadToProcess | when it's true, config will be available globally in process.config | false | dotenv | configuration for .env file | | | dotenv.path | filepath to .env file | ./env | | dotenv.silent | should not warn if .env file is missing | true | | localConfig | configuration object for local config | | | localConfig.path | path to local config | './config.local.yml' | | localConfig.force | specify if localConfig should be always loaded, fails if doesn't exists | false

Reasons to implement this

Why yet another npm module for app configuration?

Yes, you are right, there are plenty of them, you may know node-yaml-config or yaml-config, but none of them actually conform with something I would call "good manners". What are they?

  • You should NOT define special blocks of configuration for each of your environments. If you do this, you may quickly end up with huge file containing something like this:

    dev-123-feature:
      apiLimit: 123
        
    stage-2.1:
      debug: false
    ...

    Instead, you should have just one config file and the values defined there can be overridden by "local" configuration if needed.

    In practice, you have config.yml and your CI tool (or developer) may add config.local.yml during build process to successfully setup the application with desired configuration. Important note here: This custom local configuration file should't be tracked by VCS.

  • You should be able to set credentials and secret keys easily without exposing them in source code.

    Environment variables suit the best for this - you can define them on the fly and out of the scope of the application source code.

    Yamlconf supports both environment variables and .env file, so you can define configuration in this way:

    In .env:

    REDIS=redis://yourhost:6379

    and in config.yml:

    services:
      redis: process.env.REDIS

    It should be already obvious, but I strictly discourage you to have .env tracked by VCS.

  • The philosophy behind yamlconf should match with "The twelve-factor app" methodology.

Why YAML and not JSON?

IMHO because json is not simply the appropriate format for the configuration. For example:

  • It's too verbose and no human friendly.
  • You have to edit also an already existing line when adding new object property or array item.
  • You can't use comments at all.