coffi

⚡️ A fast, lightweight, easy-to-use, configuration files loader 📄
Installation
npm install coffi
Usage
Basic Usage
import { loadConfig } from "coffi";
const { config, filepath } = await loadConfig("app.config");
const { config } = await loadConfig("tsconfig", [".json"]);
File Priority
The loader checks files in this order:
.ts files
.mts files
.cts files
.js files
.mjs files
.cjs files
.json files
You can customize this order using the extensions option.
Options
import { loadConfig } from "coffi";
import path from "node:path";
const { config } = await loadConfig({
name: "database.config",
extensions: [".js", ".json", ".ts"],
cwd: path.join(__dirname, "config"),
maxDepth: 1,
preferredPath: "path/to/config.js",
packageJsonProperty: "myConfig",
});
The preferredPath option allows you to specify an exact file path to load, bypassing the normal file search process. When provided, coffi will directly load the configuration from this path.
The packageJsonProperty option allows you to load configuration directly from a property in your project's package.json file. When specified, coffi will look for a property with this name in the nearest package.json file, and if found, will use its value as the configuration. This takes precedence over all other configuration sources, making it convenient for projects where you prefer to keep configuration in package.json.