Skip to content
Tutorials Center
My learning

Topics

Lesson 1 of 36 ยท Getting Started

What Is k6?

Learn what k6 is, why teams use it for load testing, how a k6 test is written in JavaScript but run by a Go engine, and what you can and cannot run on this site.

Every web service works fine when one person uses it. The interesting question is what happens when a thousand people use it at once, or when a marketing email sends ten times the usual traffic in a single minute. Load testing answers that question before your real users do. You send realistic traffic at a system on purpose, measure how it responds, and decide whether it is fast and stable enough.

k6 is an open-source load testing tool. You describe the traffic in a JavaScript file, and the k6 program runs it. The tool itself is a single binary written in Go, so it uses little memory and can simulate thousands of users from one laptop. Your script is plain JavaScript (ES modules), so developers can read, review and version it like any other code.

What k6 gives you

  • Tests as code. A test is a .js file in your repository. No GUI, no recorded clicks.
  • Efficient virtual users. A virtual user (VU) is one simulated visitor running your script in a loop. k6 runs many of them in parallel with a small footprint.
  • Built-in metrics. Response times, error rates, request counts and data transferred are collected automatically.
  • Pass or fail rules. Thresholds turn metrics into a verdict ("95% of requests under 300 ms") so a pipeline can fail a build.
  • Flexible traffic shapes. Scenarios describe ramps, constant rates, spikes and mixes of different user journeys.
  • Many protocols. HTTP is the core, with WebSocket, gRPC and browser tests available as modules.

You will meet each of these in this track. The overall picture looks like this:

flowchart LR
  S["Test script<br/>(JavaScript)"] --> K["k6 engine<br/>(Go binary)"]
  K -->|"many virtual users"| T["System under test"]
  T -->|"responses"| K
  K --> R["Metrics, thresholds,<br/>end-of-test summary"]

What runs on this site. The k6 binary cannot run inside your browser, and the site's code runner does not include it. The k6 scripts in this track are therefore read-only code blocks. To make the ideas tangible, nearly every lesson also has a runnable stand-in written in plain Node.js: a tiny local server and a small load generator that behaves like k6 in the way the lesson describes. Stand-ins are always labelled. They teach the concepts, but they are not k6, and numbers such as response times will differ from a real run.

Your first k6 script

This is a complete, valid k6 test. Read it from top to bottom; each piece gets its own lesson later.

JavaScript
import http from 'k6/http';
import { sleep } from 'k6';

export const options = {
  vus: 10,
  duration: '30s',
};

export default function () {
  http.get('https://test.k6.io');
  sleep(1);
}
  • import http from 'k6/http' loads k6's HTTP module. The k6/... imports are built into the binary; they are not npm packages.
  • options configures the run: here, 10 virtual users for 30 seconds.
  • The default function is the iteration. Every VU calls it again and again until time is up. It sends one GET request, then pauses for one second like a person reading a page would.

Run it from a terminal with k6 run script.js. You will install and run it for real in the next lesson.

Why JavaScript, but not Node.js

This surprises many newcomers: the script looks like Node.js code, but it does not run in Node. k6 embeds its own small JavaScript engine (a Go implementation of ECMAScript). That has consequences:

  • You cannot import fs from 'fs' or use npm packages that depend on Node APIs.
  • There is no window and no document. HTTP calls are written as straightforward calls: http.get(url) returns a response object directly.
  • Modern syntax such as const, arrow functions, destructuring, template strings and ES modules works.
  • Each VU gets its own isolated copy of your script, so global variables are per VU, not shared.

The benefit is speed and low memory: the heavy lifting (connections, timing, metrics) happens in Go, and your JavaScript only decides what to request.

A stand-in you can run

The program below is not k6. It starts a small local server and uses a plain Node.js loop with three "virtual users" sharing a budget of twelve iterations, just like vus: 3, iterations: 12 would. It shows the shape of every load test: a server, concurrent callers, and counters.

Node.js Stand-in: three virtual users hit a local server

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or process.stdin), it gets the next line from this box.

Twelve iterations were shared among three VUs, and the server saw exactly twelve requests. The real k6 does the same bookkeeping, with far more precision, and reports it in the summary you will learn to read.

The kinds of questions k6 helps answer

Question What you would test
Is the site fast under normal traffic? A steady load for several minutes
What happens at twice the traffic? A stress test that keeps raising the load
Can it survive a sudden surge? A spike test
Does it leak memory over hours? A soak test
Did last week's change slow the API? A small test in CI that fails on a threshold

The next lessons cover how to install k6 and run it, the types of load tests, and how virtual users and iterations work.

Only load test systems you own or have explicit permission to test. Pointing k6 at someone else's server can look like a denial-of-service attack and may be illegal. Use your own staging environment or a public demo host that invites testing.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What language do you write k6 test scripts in?

    Scripts are JavaScript. The k6 engine itself is written in Go, but you never need to write Go to use it.
  2. 2. Which statement about the k6 JavaScript runtime is true?

    k6 embeds a Go-based JavaScript engine. Node built-ins and npm packages that rely on them are not available.
  3. 3. What is a virtual user (VU)?

    A VU executes your iteration function repeatedly, simulating one visitor. k6 runs many of them in parallel.
  4. 4. Why are the k6 examples on this site read-only?

    The k6 binary is not available here. The site shows real k6 code read-only and adds clearly labelled Node.js stand-ins to demonstrate the concepts.

Summary

  • Load testing measures how a system behaves under many simultaneous users.
  • k6 is an open-source tool: scripts in JavaScript, engine in Go.
  • A virtual user repeatedly runs the default function; options sets the load.
  • k6 is not Node.js: no fs, no npm packages, per-VU global state.
  • Metrics, thresholds and scenarios turn a script into a repeatable test.
  • Only test systems you are allowed to test.

Next: Installing k6 and Running Your First Test