Skip to content
On this page

File

Overview

Loads configuration from files. Files can be of any type as long as there is a Parser available.

Installation

bash
npm install @willsoto/node-konfig-file
bash
yarn add @willsoto/node-konfig-file
bash
pnpm add @willsoto/node-konfig-file

Usage

typescript
import * as Konfig from "@willsoto/node-konfig-core";
import { FileLoader } from "@willsoto/node-konfig-file";
import process from "node:process";
import path from "node:path";

const parser = new Konfig.JSONParser();

const loader = new FileLoader({
  files: [
    {
      path: path.join(process.cwd(), "config.json"),
      parser,
    },
    {
      path: path.join(process.cwd(), `${process.env.NODE_ENV}.json`),
      parser,
    },
  ],
});

Options

NameRequiredDescription
filesyesAn array of files to load. See File for more information.

File

NameRequiredDescription
pathyesThe path to the file.
parseryesThe parser to use. See Parsers for more information.