xk6-dotenv
A k6 extension that loads env vars from a .env file.
This extension follow the convention 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.
Hierarchy Priority |
Filename |
K6_ENV |
Should I .gitignore it? |
Notes |
1st (highest) |
.env.development.local |
development |
Yes! |
Local overrides of environment-specific settings. |
1st |
.env.test.local |
test |
Yes! |
Local overrides of environment-specific settings. |
1st |
.env.production.local |
production |
Yes! |
Local overrides of environment-specific settings. |
2nd |
.env.local |
(any expect false ) |
Definitely. |
Local overrides. This file is loaded for all environments except test . |
3rd |
.env.development |
development |
No. |
Shared environment-specific settings |
3rd |
.env.test |
test |
No. |
Shared environment-specific settings |
3rd |
.env.production |
production |
No. |
Shared environment-specific settings |
Last |
.env |
(any expect false ) |
Depends |
The Original |
The underlying implementation is https://github.com/joho/godotenv
Built for k6 using xk6.
Usage
Import an entire module's contents:
import * as dotenv from "k6/x/dotenv";
Import a single export from a module:
import { parse } from "k6/x/dotenv";
API
This extension can be used as a library:
For complete API documentation click here!
Build
To build a k6
binary with this extension, first ensure you have the prerequisites:
Then:
- Install
xk6
:
$ go install go.k6.io/xk6/cmd/xk6@latest
- Build the binary:
$ xk6 build --with github.com/ecolytiq-team/xk6-dotenv@latest