https://github.com/codex-team/config-loader
Config loader for Cloud Native applications
https://github.com/codex-team/config-loader
Last synced: 4 months ago
JSON representation
Config loader for Cloud Native applications
- Host: GitHub
- URL: https://github.com/codex-team/config-loader
- Owner: codex-team
- License: apache-2.0
- Created: 2022-06-16T10:19:01.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2023-08-28T21:35:13.000Z (almost 3 years ago)
- Last Synced: 2024-04-24T09:25:23.372Z (about 2 years ago)
- Language: TypeScript
- Homepage:
- Size: 1.13 MB
- Stars: 0
- Watchers: 4
- Forks: 1
- Open Issues: 9
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# config-loader
Config loader for Cloud Native applications
## Features
- Configuration via YAML files
- Combining and inheriting a configuration from multiple files
- Override configuration values with environment variables
- Provide default values for configuration
## What's not included
- Reading command line arguments with config files locations
- Configuration validation
## Installation
```bash
npm install @codex-team/config-loader
yarn add @codex-team/config-loader
```
## Usage
In this example we will load configuration from `app-config.yaml` and `app-config.local.yaml` files.
[Zod](https://zod.dev/) is used for configuration validation, but you can use any other library.
```ts
import {loadConfig} from '@codex-team/config-loader';
import {z} from 'zod';
const AppConfig = z.object({
host: z.string(),
port: z.number(),
});
export type AppConfig = z.infer;
const defaultConfig: AppConfig = {
host: '0.0.0.0',
port: 3000,
};
const paths = [
`./app-config.yaml`,
`./app-config.local.yaml`,
];
const loadedConfig = loadConfig(...[defaultConfig, ...paths]);
const appConfig = AppConfig.parse(loadedConfig);
export default appConfig;
```