Product
Introducing License Enforcement in Socket
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
LittleConf is a simple library for loading project configuration files.
import { getConfig } from 'littleconf';
const config = await getConfig();
This will load a YAML configuration file named <PackageName>.conf
or <PackageName>.conf.js
from the package root directory. By default, the package name is discovered from the project's package.json file.
LittleConf will also look for a file named <PackageName>-defaults.conf
or <PackageName>-defaults.conf.js
in the package root directory. This file is merged with the main config file and can supply
defaults. By convention, the defaults file should be committed to the source repository, and the main config file should not.
LittleConf looks for the main config file under the following namess. It uses the first one that applies:
filenameOverride
option.-c
command-line argument.PACKAGE_NAME_CONFIG
.filename
option.package-name.conf
If the above does not yield an absolute path, LittleConf first looks for the file in the package root directory, then in /etc
.
In the config file, you can specify a set of configuration values that are only applied when a given "environment" is configured. The config file with environments looks like this:
foo: "banana"
bar: 12
environments:
local:
foo: "apple"
prod:
foo: "pear"
The envionment is normally selected using the NODE_ENV
or PROJECT_NAME_ENV
environment variable, but can also be selected using the following methods (the first that exists is used):
environmentOverride
option.--config-env
command-line argument.PROJECT_NAME_ENV
environment variable.NODE_ENV
environment variable.defaultEnvironment
option.To allow LittleConf to handle command-line arguments, it needs to be supplied with the argv
option. This can come from a standard argument parsing package like optimist
or yargs
.
const argv = require('yargs').argv;
const config = require('littleconf').getConfig({ argv: argv });
Individual settings can be overridden using command-line arguments or environment variables. Environment variables are named PROJECT_NAME_CONFIG_SETTINGNAME
and command-line
arguments look like --config-setting-SETTINGNAME
.
These options can be supplied in the argument to getConfig()
.
argv
- The set of command-line arguments.projectName
- The name of the project. Defaults to the name
property in package.json.environmentOverride
- Force a specific config environment value.cliArgumentEnvironment
- The name of the CLI argument to use for selecting the config environment. Defaults to "config-env".rootDir
- The root directory of the project. By default this is determined by using require.main
and traversing upwards until
a package.json is found.envVariableEnvironment
- Selects a specific name for the environment variable to determine the config environment rather than
the default of PROJECT_NAME_ENV
.defaultEnvironment
- Sets the default config environment. Defaults to "local".defaultsFilename
- Sets the filename to use for the defaults file. Normally "projectname-defaults.conf".filenameOverride
- Forces the name/path of the main config file.filename
- Default name of the main config file. Defaults to "projectname.conf".cliArgumentFile
- Name of the command-line argument to specify the config file. Defaults to "c".envVariableFile
- Name of the environment variable to specify the config file. Defaults to PROJECT_NAME_CONFIG
.FAQs
Simple and small library for loading configuration files and options
The npm package littleconf receives a total of 2 weekly downloads. As such, littleconf popularity was classified as not popular.
We found that littleconf demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
Product
We're launching a new set of license analysis and compliance features for analyzing, managing, and complying with licenses across a range of supported languages and ecosystems.
Product
We're excited to introduce Socket Optimize, a powerful CLI command to secure open source dependencies with tested, optimized package overrides.