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

@fp8/simple-config

v0.5.2

Published

Simple Config Reader

Downloads

148

Readme

Simple Config Reader

Read the config file from ./[etc|config]/${FP8_ENV}/ directory. The file can be [app|config].[json|yaml]. Only .json and .yaml extension are supported. Any other file extension found or passed will not be loaded.

Note: Package under @fp8 contains Farport Software's specific view on how the code of project is to be organized.

Usage

Assuming that you have a following configuration file saved in your ./config/app.yaml:

name: database-config
username: user-123
password: password-234

Define the following class:

class ConfigData {
    name: string;
    username: string;
    password: string;
}

Load the config using ConfigStore:

const store = new ConfigStore(ConfigData);
const config = store.data; // would be of type ConfigData

console.log('username: ', config.username);
// output user-123

Config Model

The configuration model's properties can be decorated with class-validator to ensure that config data loaded is indeed thie expected format. ConfigStore raises EntityCreationError if validation fails.

It is also possible to skip the definition of the config model by returning a generic IJson and obtain the config value using the ConfigStore.get method:

name: test-app
db:
    username: user-123
    password: password-234
const store = new ConfigStore<IJson>();

console.log('username: ', store.get('db.username'));
// output user-123

Config Options

The IConfigStoreOptions allow customization on how the config should be loaded.

env

The config file are loaded from ./[etc|config]/${FP8_ENV}/ directory. This env option overrides value from FP8_ENV and search the config from ./[etc|config]/${env}/ directory.

configFileName

The primary configuration file name. This is normally app.[json|yaml] or config.[json|yaml] but can be specified via this option.

loadAll

If this option is set, all the files from the config directory are loaded. The logic is:

  1. Find the primary config file
  2. Load all the supported file from the config directory
  3. Append the name of the config file without extension to the config data

Assuming that you have the following files in the config directory:

app.yaml:

name: yaml-config

device.json:

{ "id": "id-abc" }

The expected loaded config data would be:

class ConfigData {
    app: { name: string };
    device: { id: string };
}

entries

This option allows additinal entries to be added to the config data. This is useful if you wish to add secret from vaults to config upon application startup.

Templating

Templating support is done via mustache.

name: url configurator
domain: example.com
url: "https://{{domain}}/info"
env: "ENV.FP8_ENV"

Notice env file can be used as part of templating by prefixing the variable name with ENV..

## Validation

The config store will always validate the loaded config if following syntax is used:

const store = new ConfigStore(ConfigData);

However, if following syntax is used, the validation will be skipped:

const store = new ConfigStore<ConfigData>();

Upon validation error, the EntityCreationError is throw. To see what fields fails the validation, use EntityCreationError.fields property.