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

ini-config-loader

v1.0.1

Published

env and config file loader

Downloads

142

Readme

ini-config-loader

Lean .env and config.ini file loader with 0 dependencies.

install

npm install ini-config-loader

basic usage

$ tree
 . 
 ├── node_modules
 │    ...
 ├── config 
 │    ...
 │    └── my-module.ini
 ├── .env
 └── .env.local
const { 
    init, readEnv, readJSONEnv, readConf, readJSONConf 
} = require('ini-config-loader')

init().then(() => {
    const envValue = readEnv('EXAMPLE_ENV_VALUE')
    const envArrayValue = readJSONEnv('EXAMPLE_ENV_ARRAY'),
    const configValue = readConf('my-module', 'EXAMPLE_CONFIG_VALUE'),
    const configObjectValue = readJSONConf('my-module', 'EXAMPLE_CONFIG_OBJECT'),
})

functionality

init

init searches from the node_modules folder downwards the .env file. The folder with the .env file is the base directory. If there is no .env file the root directory (/) becomes the base directory. It loads the .env and the .env.local file from the base directory if present. It loads all *.ini files from the config folder above the base directory. It finishes when all files are parsed.

On parsing the lines of a file are split on the first = and whitespace is trimmed off.

   EXAMPLE_VAL = hello world!  #no comment

will be evaluated to something like this

{
    "EXAMPLE_VAL":"hello world!  #no comment"
}

Comments can be placed by not using an =.

This is an example value:  
EXAMPLE_VAL=hello world!

All values are string. The readJSON* functions apply JSON.parse to the value.

readEnv / readJSONEnv

readEnv(valueName) returns a value defined in the .env or the .env.local.

If the value is defined in the .env and the .env.local the value of the .env.local is used.

If non such value is defined it returns null.

readConf / readJSONConf

readConf(moduleName, valueName) returns a value defined in the config/${moduleName}.ini.

If non such value is defined it returns null.

absolutePath

absolutePath(relativePath) prefixes a relative Path by the absolute path of the base directory. If the relative Path is an absolute Path (it starts with '/') it is not altered.

isDevEnv

Checks whether the readEnv('NODE_ENV') value does not equal production. If it is not set, the process.env.NODE_ENV value is checked against.

onConfigChanged

If parseInt(readEnv('CONFIG_LOADER_TIMEOUT')) evaluates to a positive integer it defines an intervall in milliseconds after which the .env, .env.local and config/*.ini files are checked for changes. If a change is detected all values are hot reloaded.

A callback which is registered by onConfigChanged(callback) is called after the reload has occurred.