Skip to content

AckeeCZ/configuru

Folders and files

NameName
Last commit message
Last commit date
Jul 19, 2024
Jul 12, 2022
Jul 18, 2024
Jun 3, 2024
Jul 18, 2024
Apr 10, 2019
Oct 1, 2020
Apr 10, 2019
Sep 25, 2020
Apr 10, 2019
Oct 1, 2020
Oct 1, 2020
Apr 10, 2019
Aug 13, 2024
Oct 1, 2020
Jul 16, 2024
Jul 18, 2024
Oct 1, 2020
Oct 1, 2020
Oct 1, 2020

Repository files navigation

Configuru

Manage the configuration of your Nodejs application with multiple environments and custom preferences, utilizing Configuru in CI and development as well!

Improve the DX when managing the configuration files, get inline help and more with the VS Code extension.

Features

Configuru is a library for configuration management. Merge default project configuration with your user config, you can link yo your project. Atop of that, override your configuration with system environment variables.

  • 😌 Tailored for multi-developer comfort
  • ✨ Cast and transforms inputs to the correct type
  • πŸ’™ Typescript friendly
  • πŸ’ͺ Designed for multi-environment apps
  • πŸ™ˆ Anonymized configuration for logger
  • πŸ’¬ JSONC support

Getting started

  1. Install
npm install configuru
  1. Create .env.jsonc in root of your project, add defaults or placeholders.
{
  // HTTP server
  "SERVER_PORT": 3000 // port the server will be listening on
}
  1. (optional) As a developer (or environment), create a custom override file (e.g. ~/.env/my-project.jsonc) and save the path in your CFG_JSON_PATH.

  2. Create a configuration module (e.g. config.ts)

import { createLoader, values } from 'configuru'

// create loader that cascades overrides and creates a config storage
const loader = createLoader()

// Pass configuration schema to `values` transformer to get configuration
export default values({
  server: {
    // use loader accessors, place them in custom structure
    // loader parses correct type from store
    port: loader.number('SERVER_PORT'),
  },
})
  1. Use your configuration params throughout your app
import config from './config' // e.g. { server: { port: 3000 } }

console.log(config.server.port) // 3000

Docs

See also

  • config - Simple JSON config loader using NODE_ENV
  • dotenv - Load your configuration file to process.ENV
  • cosmiconfig - Traverse your filesystem to load find your lost configuration file
  • configstore - KV storage for configuration
  • figgy-pudding - Config object builder / storage

Know other popular projects that solve the same issue? Open a PR to help people find what they need!

License

This project is licensed under MIT.