Uploading k6 Scripts and Data Files

Every k6 test on LoadFocus runs from a script you write. The Script Configuration section on the New k6 Test page is where you upload that script, along with any data files it reads at run time.

What you need

  • A k6 test script, written in JavaScript (.js) or TypeScript (.ts). This is the only required file.
  • Data files, if your script reads external data. A CSV of user accounts or a JSON of payloads are the common cases.

Uploading your files

Open New k6 Test and scroll to Script Configuration. You can either drag your files onto the upload area, or click Upload k6 Scripts & Files to browse for them.

Upload the script and its data files together. They land in the same directory when the test runs, so a script that reads users.csv finds it right next to itself.

Supported file types

ExtensionTypical use
.jsYour k6 test script
.tsA TypeScript test script
.csvRow data, such as accounts or search terms
.jsonStructured payloads or fixtures
.txtPlain-text data
.env, .propertiesConfiguration values your script reads

Reading a data file from your script

k6 reads files with open(), and the file sits alongside your script, so a relative path is all you need. Load data once in the init stage rather than per iteration, so every virtual user shares it:

import { SharedArray } from 'k6/data';
import http from 'k6/http';
const users = new SharedArray('users', function () {
return open('./users.csv')
.split('\n')
.slice(1)
.filter(Boolean)
.map((line) => {
const [username, password] = line.split(',');
return { username, password };
});
});
export default function () {
const user = users[Math.floor(Math.random() * users.length)];
http.post('https://example.com/login', {
username: user.username,
password: user.password,
});
}

SharedArray keeps one copy of the data in memory for all virtual users. Without it, every virtual user parses its own copy, which costs memory you would rather spend on load.

How files behave across engines

A test with enough virtual users runs on more than one k6 engine. Every engine receives the same uploaded files, so each one has its own copy of your data.

That matters when your data must not be reused. If each row represents a single-use account or coupon, two engines can pick the same row, because neither knows what the other has taken. Where a value must be consumed exactly once, have the script request it from an endpoint you control instead of reading it from a file.

After uploading

Your files are listed under the upload area, where you can remove any you added by mistake and upload a replacement. Once the script is in place, configure your virtual users, duration, and test locations, then start the test.