# Config

Config in FhyTS is a singleton component responsible for loading and providing access to application configuration from an external file, such as JSON. This allows you to centrally and consistently manage the environment, application settings, and global parameters.

## General Concepts

* Uses a singleton pattern, ensuring that only one instance of the configuration exists at runtime.
* Loads a configuration file from a specified path (typically **config/App.Config.json**).
* Provides secure access to configuration values ​​with fallbacks/defaults.

## API Reference

| Method / Property | Type | Description |
| ------------------------ | ---------------------------------------------------- | ----------------------------------------------------------------------- |
| `getInstance()` | `static => Config` | Gets a single instance of `Config`. |
| `load(filePath)` | `(filePath: string) => void` | Loads and parses a configuration file (JSON). |
| `get(key, defaultValue)` | `(key: string, defaultValue?: any) => any` | Gets the configuration value based on the key, with the option of a default value. |

## Usage Example

**Loading Configuration at Entry Point**

```javascript
import { Config } from 'fhyts';

const config = Config.getInstance();
config.load('./config/App.Config.json');
```

**Accessing Configuration Values**

```javascript
const appName = config.get('app_name', 'DefaultApp');
const isDebug = config.get('debug', false);
```

> If the key is not found, then the default value will be returned.

## Example JSON File Structure

```json
// config/App.Config.json
{
  "app_name": "FhyTS App",
  "debug": true,
  "port": 3000,
  "minified": false
}
```

## Characteristics

* **Type Safe**: Supports fallback/default values ​​to prevent errors if a key is unavailable.
* **Lazy Loading**: Configuration data is only loaded when **load()** is called.
* **Global Access**: Can be used throughout the application because it is a singleton.

## Best Practices

* Load the configuration file only once, at the application entry point (**server.ts**).
* Use **get(key, defaultValue)** to prevent errors when a key is unavailable.
* Use a consistent and documented structure in the JSON configuration file.

## Next

Once you understand how to use Config, you can move on to the [Modules](#modules) section to learn how to dynamically load and manage individual modules in your application.