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

slay-config

v2.3.0

Published

Standard, sane defaults for config in slay apps.

Downloads

183

Readme

slay-config

Standard, sane defaults for config in slay apps.

Usage

Simply add slay-config as a preboot in your standard preboot location. Generally speaking it should be towards the top of your application's preboots since it will be loading in configuration that others will need.

lib/preboot.js

module.exports = function (app, options, done) {
  // ...

  app.preboot(require('slay-config')({
    //
    // Any defaults for configuring the `nconf` instance
    // attached to the `app`.
    //
  }));

  // ...
};

This will setup your application config to load from (in-order):

  1. Any forced programmatic overrides
  2. CLI arguments
  3. Environment variables
  4. Config file (defaulting to config/{env}.json)
  5. [Optional] Secure file

Options

app.preboot(require('slay-config')(defaults));

Where defaults can have the following properties (all of which are optional):

  • overrides: {Object} Any overrides for your application's config.
  • argv: {Object} Settings for loading CLI arguments into application config.
  • env: {Object} Settings for loading environment variables into application config.
  • file: {Object} Settings for loading a file to configure your application. Defaults to ${app.root}/config/${env}.json.
  • secure: {String} If set, will look for secure nconf settings in the config property at that location.

Default CLI args and ENV vars

If you do not have the luxury of being able to pass in explicit options to configure a slay-config, we have added the ability to configure slay-config with ENV vars or CLI args.

CLI Args:

  • config: The file path for the configuration file to load.
  • secure-file: The file path for the secure configuration file to load.
  • secure-secret: The file path for the secret used to encrypt the secure configuration file.

ENV vars:

  • CONFIG
  • SECURE_FILE
  • SECURE_SECRET

Loading encrypted secure config

This can be done in one of two ways:

1. Specifying the secure option in your cleartext config file

When specifying this option be aware that all relative file paths will resolved from app.root.

config/development.json

{
  // ... other configuration values
  "secure": {
    "file": "./config/secure/development.json",
    "secretPath": "./config/secure/development.key"
  }
}
2. Specifying the secure option when requiring slay-config
  app.preboot(require('slay-config')({
    secure: {
      file: './config/secure/development.json'
      secretPath: './config/secure/development.key'
    }
  }));

Changing configuration loading

Often (and mainly for testing purposes) it is often useful to change the options passed into to your configuration loader so as to turn on or off certain values (e.g. turning off logging in your tests).

With this in mind any defaults passed to slay-config can be overridden by the config property passed to app.start e.g.:

lib/preboot.js

module.exports = function (app, options, done) {
  // ...

  app.preboot(require('slay-config')({
    file: { file: path.join(app.root, 'config', app.env + '.json') }
  }));

  // ...
};

Can be overridden to a test configuration file when calling app.start:

app.start({
  config: {
    file: { file: path.join(app.root, 'test', 'config', app.env + '.json') }
  }
}, callback);

Tests

npm test

License

MIT

Contributors: Fady Matar, Charlie Robbins