Skip to content

neolao/config-yaml

Repository files navigation

Node version Version Build status dependencies Status devDependencies Status

config-yaml

YAML configuration for NodeJS

Basic example

config/default.yml:

foo: "bar"
list:
    - 1
    - 2
    - 3
import configYaml from "config-yaml";

const config = configYaml(`${__dirname}/config/default.yml`);

console.log(config.foo); // "bar"
console.log(config.list[1]); // 2

Example with imports directive

config/production.yml:

imports:
    - { resource: "default.yml" }
    - { resource: "routing/api.yml", property: "routing.api" }

foo: "hello"
tic: "tac"
import configYaml from "config-yaml";

const config = configYaml(`${__dirname}/config/production.yml`);

console.log(config.foo); // "hello"
console.log(config.routing.api); // Configuration from routing/api.yml

Available variables

Variable Description
%__dirname% Directory path of the current YAML file
%__filename% Current YAML file path