How to create file and write something to it?

Dear madam/sir, I am trying to use k6 to create a txt file to the current directory and write something to it, could you please tell me how I can do it?

Thanks,
Ken

Hello @Ken! You need to use an extension like this GitHub - avitalique/xk6-file: k6 extension for writing files

1 Like

Thank you Maksimall89, I will try it soon.

1 Like

Hi, Maksimall89,

I have installed ‘GO’ and then installed “xk6” by executing command “go install go.k6.io/xk6/cmd/xk6@latest”, but when I execute “xk6 version”, there is exception like below:

C:\Users\kwu1\Desktop>xk6 version
go: cannot match “all”: go.mod file not found in current directory or any parent directory; see ‘go help modules’
2022/08/10 10:52:36 [ERROR] exec [go list -mod=readonly -m -f={{if .Replace}}{{.Path}} => {{.Replace}}{{end}} all]: exit status 1:

And then k6 run my script, there is exception: ERRO[0001] unknown module: k6/x/file
Seems that the module is not installed successfully.
Could you please tell me what I should do.

Thanks,
Ken

Hi, Maksimall89,

It is OK now after I run command “xk6 build v0.36.0 --with github.com/avitalique/xk6-file@latest”, file can be created and written.
Thank you very much.

Thanks,
Ken

1 Like