Load data file from command line

Is there any possibility to load a json data file from command line rather than using the below in testscript.js file ?

const data = JSON.parse(open("./data.json"));

You can pass the filename as an environment variable like this k6 run --env MY_CONFIG_FILE=production.json, and then in your script you can have something like this:

const data = JSON.parse(open(__ENV.MY_CONFIG_FILE));
2 Likes

thanks, it sounds to be a working solution.

1 Like