Skip to content

Uploading k6 Scripts and Data Files

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

  • 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.

Open New k6 Test. Step 1 Your test script is at the top of the page. 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.

Extension Typical use
.js Your k6 test script
.ts A TypeScript test script
.csv Row data, such as accounts or search terms
.json Structured payloads or fixtures
.txt Plain-text data
.env, .properties Configuration values your script reads

You can upload up to 10 files per test, each up to 100 MB.

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.

A test with enough virtual users runs on more than one load generator. Every load generator 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 load generators 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.

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.