Hi k6 community, I created a k6 extension that loads env vars from an .env file. I’m looking forward for your feedback…
When I try to use your library:
unknown module: k6/x/dotenv
Same here. I got it working by building a custom k6 binary. Is that the only way to use this extension @szkiba?
Hello @PaulMEdwards. Welcome to the community! I can affirm that building the custom binary with xk6 is the only way to use the extension.
What do you mean by “building the custom binary”
I would wish for this to be as simple as:
import * as dotenv from "k6/x/dotenv";
export default function (token) {
console.log("the env var is ", dotenv.get("TEST_VAR"));
}
Thanks for that suggestion @Murat! I’m sure many will find it useful.
For those who prefer to not install any external tools for this, loading an env file is also possible with some shell tricks.
Hi @szkiba
I have a problem using your module
import { parse } from "k6/x/dotenv";
dev_env = parse(".env.dev")
ERRO[0000] GoError: unknown module: k6/x/dotenv
So should I install & build it first?
Hi @nktedo001 !
You have to build a custom k6 binary to use this extension with the following command:
xk6 build --with github.com/szkiba/xk6-dotenv@latest
how does this work on CI for example, will it still swap key values okay? Obviously there’s not going to be a .env file on CI…