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

@brickblock/strong-config

v0.10.0

Published

Safe config for node

Downloads

20

Readme

@brickblock/strong-config

strong-config is a library that does 4 things:

  1. Loads a file (yaml or json) into memory as an object
  2. Optionally, decrypts a sops encrypted file
  3. Optionally, validates the config against a schema defined in json-schema
  4. Substitutes environment variables with the loaded and decrypted values from memory

Installation

The library should be installed as a dependency:

yarn add @brickblock/strong-config

Conventions

  • strong-config will read the config from config/${NODE_ENV}.[yml|yaml|json]
  • If the config file contains a sops key, it is assumed to be encrypted and it will be decrypted using sops. sops must already be available on your $PATH
  • If a config/schema.[yml|yaml|json] exists, the resulting config object is validated against the schema using json-schema
  • If the config file has any instances of ${ENV_VAR} it will be substituted with the value defined in the environment.

Usage

NODE_ENV=production yarn start
/* config/production.json */

"logger": {
  "name": "my-prod-logger"
  "level": "INFO"
}
/* index.js */

const config = require('@brickblock/strong-config').load()
// config = { logger: { name: 'my-prod-logger', level: 'INFO' }}

const logger = bunyan.createLogger(config.logger)

Flow Types for Schemas

When given a valid json-schema, this package will automatically generate a flow type of the schema to allow strongly-typing the config-object in consuming applications.

Caveats

  1. The consuming application must be executed with NODE_ENV=development to trigger the flow type generation
  2. Schema must be a JSON file

Using the type

When using .load(), flow will automatically pick up the auto-generated type definition at @brickblock/strong-config/build/index.flow and will use it to strongly-type the config-object:

/* ./src/index.js */

// @flow
const config = require('@brickblock/strong-config').load()

// flow will warn that the `config` object doesn't have the key `nonExistentConfigKey`!
const ProblematicComponent = () => <div>{config.nonExistentConfigKey}</div>

Next Steps

Follow the Onboarding tutorial