K6 dotenv support

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

1 Like

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.

1 Like

Thank you for that confirmation, @javaducky.

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"));

Here’s a painless solution to environment variables with k6; just use dotenv-cli.


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.