config-lev

A simple json config loader

Usage no npm install needed!

<script type="module">
  import configLev from 'https://cdn.skypack.dev/config-lev';
</script>

README

config-lev

Build Status npm version

Super simple to use

A simple config loader, only support json.

Installation

npm install config-lev

Usage

Usually, you will create a config directory including default.json, test.json and production.json in your project root directory. And using NODE_ENV=test to overwrite(merge) default.json with test.json is very helpful. Specifing environment variables such as PORT=3000 can also be used to overwrite with highest priority.

First, Invoking the module without params to load the config in process current working dir is necessary:

require("config-lev").load();
const config = require("config-lev");

or

const config = require("config-lev").load();

Alternatively, invoking with path string can be used to overwrite(merge) the config of process current working dir:

require("config-lev").load("path/to/config");
const config = require("config-lev");

or

const config = require("config-lev").load("path/to/config");

After step 1, require("config-lev") will become one global plain javascript object with only configs entries in it. When you need it:

const config = require("config-lev");

And you can modify this plain object freely.