2024-01-02 15:13:43 -06:00
|
|
|
---
|
|
|
|
title: Environment Variables
|
|
|
|
description: Configure your application with environment variables.
|
|
|
|
---
|
|
|
|
|
|
|
|
# Environment Variables
|
|
|
|
|
|
|
|
flecks has first-class support for configuring your application through environment variables.
|
|
|
|
|
|
|
|
## Example
|
|
|
|
|
|
|
|
`@flecks/core` defines a configuration key `id`. We've already seen how it can be configured like
|
|
|
|
so:
|
|
|
|
|
|
|
|
```yml
|
|
|
|
'@flecks/core':
|
|
|
|
id: 'foobar'
|
|
|
|
```
|
|
|
|
|
|
|
|
When running your application in different execution environments (say, production) you may want to
|
2024-01-04 18:39:21 -06:00
|
|
|
override configuration such as this. This is done by like so:
|
2024-01-02 15:13:43 -06:00
|
|
|
|
|
|
|
### Syntax
|
|
|
|
|
|
|
|
```javascript
|
2024-01-04 18:39:21 -06:00
|
|
|
`FLECKS_ENV__${Flecks.environmentalize(fleck)}__${key}`
|
2024-01-02 15:13:43 -06:00
|
|
|
```
|
|
|
|
|
2024-01-04 18:39:21 -06:00
|
|
|
:::tip
|
2024-01-02 15:13:43 -06:00
|
|
|
|
2024-01-04 18:39:21 -06:00
|
|
|
As an example, `@flecks/core`'s `id` key is set using the following variable:
|
2024-01-02 15:13:43 -06:00
|
|
|
|
|
|
|
```bash
|
2024-01-04 16:11:48 -06:00
|
|
|
FLECKS_ENV__flecks_core__id=foobar
|
2024-01-02 15:13:43 -06:00
|
|
|
```
|
|
|
|
|
|
|
|
<details>
|
2024-01-04 18:39:21 -06:00
|
|
|
<summary>`Flecks.environmentalize` implementation</summary>
|
2024-01-02 15:13:43 -06:00
|
|
|
```javascript
|
|
|
|
static environmentalize(path) {
|
|
|
|
return path
|
2024-01-04 18:39:21 -06:00
|
|
|
// - `@flecks/core` -> `flecks_core`
|
2024-01-02 15:13:43 -06:00
|
|
|
.replace(/[^a-zA-Z0-9]/g, '_')
|
2024-01-04 16:11:48 -06:00
|
|
|
.replace(/_*(.*)_*/, '$1');
|
2024-01-02 15:13:43 -06:00
|
|
|
}
|
|
|
|
```
|
|
|
|
</details>
|
|
|
|
|
2024-01-04 18:39:21 -06:00
|
|
|
Note that the fleck path and key are still case-sensitive. This is because they are
|
2024-01-02 15:13:43 -06:00
|
|
|
user-defined.
|
|
|
|
|
|
|
|
:::
|