github.com/ecolytiq/xk6-dotenv@v0.2.2-0.20220902071434-058cfd60158b/README.md (about)

     1  # xk6-dotenv
     2  
     3  A k6 extension that loads env vars from a .env file.
     4  
     5  This extension follow the [convention](https://github.com/bkeepers/dotenv#what-other-env-files-can-i-use) for managing multiple environments (i.e. development, test, production). The actual environment name came from an env variable named `K6_ENV`. Setting this to `false` value disable the convention mentoined above and no .env file will be loaded automatically.
     6  
     7  | Hierarchy Priority | Filename                 | K6_ENV                 | Should I `.gitignore`it? | Notes                                                        |
     8  | ------------------ | ------------------------ | ---------------------- | ------------------------ | ------------------------------------------------------------ |
     9  | 1st (highest)      | `.env.development.local` | development            | Yes!                     | Local overrides of environment-specific settings.            |
    10  | 1st                | `.env.test.local`        | test                   | Yes!                     | Local overrides of environment-specific settings.            |
    11  | 1st                | `.env.production.local`  | production             | Yes!                     | Local overrides of environment-specific settings.            |
    12  | 2nd                | `.env.local`             | (any _expect_ `false`) | Definitely.              | Local overrides. This file is loaded for all environments _except_ `test`. |
    13  | 3rd                | `.env.development`       | development            | No.                      | Shared environment-specific settings                         |
    14  | 3rd                | `.env.test`              | test                   | No.                      | Shared environment-specific settings                         |
    15  | 3rd                | `.env.production`        | production             | No.                      | Shared environment-specific settings                         |
    16  | Last               | `.env`                   | (any _expect_ `false`) | Depends                  | The Original                                                 |
    17  
    18  
    19  The underlying implementation is https://github.com/joho/godotenv
    20  
    21  Built for [k6](https://go.k6.io/k6) using [xk6](https://github.com/grafana/xk6).
    22  
    23  ## Usage
    24  
    25  Import an entire module's contents:
    26  ```JavaScript
    27  import * as dotenv from "k6/x/dotenv";
    28  ```
    29  
    30  Import a single export from a module:
    31  ```JavaScript
    32  import { parse } from "k6/x/dotenv";
    33  ```
    34  
    35  ## API
    36  
    37  This extension can be used as a library:
    38  
    39  - [parse](docs/README.md#parse)
    40  - [stringify](docs/README.md#stringify)
    41  
    42  For complete API documentation click [here](docs/README.md)!
    43  
    44  ## Build
    45  
    46  To build a `k6` binary with this extension, first ensure you have the prerequisites:
    47  
    48  - [Go toolchain](https://go101.org/article/go-toolchain.html)
    49  - Git
    50  
    51  Then:
    52  
    53  1. Install `xk6`:
    54    ```bash
    55    $ go install go.k6.io/xk6/cmd/xk6@latest
    56    ```
    57  
    58  2. Build the binary:
    59    ```bash
    60    $ xk6 build --with github.com/ecolytiq-team/xk6-dotenv@latest
    61    ```