Extract a generated value from script and store in a file

Hi @namratanirjharini74

Welcome to the community forum :wave:

To add to what @Elibarick mentioned, k6 core does not yet support writing to files. You can follow the issue Provide a file storing API 路 Issue #3017 路 grafana/k6 路 GitHub, and :+1: to help prioritize the implementation.

You鈥檒l also find that using a node module with Webpack might not work. From the docs:

k6 is not NodeJS, nor is it a browser. Packages that rely on APIs provided by NodeJS, for instance, the os and fs modules, will not work in k6. The same goes for browser-specific APIs like the window object.

You can find a good explanation of why fs is not supported on Write data to file - #2 by imiric.

While this is not possible in k6 core, you can use a community extension like GitHub - avitalique/xk6-file: k6 extension for writing files to write to a file. And there are also alternatives to using an extension to send the data to Redis, or a database. If you don鈥檛 necessarily need a local file.

I hope this helps.

Cheers!

1 Like