Getting Started with k6: Modern Load Testing in JavaScript

An introduction to k6, Grafana's open-source load testing tool, and why its code-first JavaScript scripting model fits modern CI/CD workflows.

· By perf-test.com Editorial · AI-assisted
k6getting-startedjavascript

k6 (now part of Grafana Labs) is an open-source load testing tool built around a simple idea: load test scripts should be plain code, written in JavaScript, that lives in your repository like any other source file — not a GUI-authored XML or binary project format.

Installation

k6 ships as a single compiled binary (Go under the hood, scripted via a JavaScript runtime embedded inside it) — no JVM, no separate runtime dependency. Install via your OS package manager (brew install k6, apt install k6, or download a binary directly), then run k6 version to confirm.

A minimal script

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

export default function () {
  http.get('https://test.k6.io/');
  sleep(1);
}

Run it with:

k6 run --vus 10 --duration 30s script.js

This runs 10 virtual users in a loop (the default function body, repeated) for 30 seconds, each pausing 1 second between iterations.

Why JavaScript, not a GUI

Because the script is just code, it diffs cleanly in pull requests, runs identically locally and in CI, and is easy for any team already writing JavaScript/TypeScript elsewhere to pick up without learning a new tool’s GUI paradigm. This is k6’s core differentiator versus JMeter and LoadRunner’s GUI-and-project-file-centric models.

Checks vs assertions

k6 uses check() calls (similar in purpose to JMeter’s assertions) to validate responses without failing the entire test run on a single bad check — checks are recorded as pass/fail metrics, visible in the summary, while thresholds (covered in a later article in this series) are what actually fail the test run based on aggregate criteria.

The metrics k6 reports by default

Out of the box, k6 reports http_req_duration (with percentiles), http_req_failed rate, iterations/sec, and virtual user count — a reasonable default summary without needing any extra configuration, unlike JMeter where you typically add specific listeners to get equivalent detail.

Where this series goes

This is the first in a short k6 series covering writing more realistic scripts, scenarios and executors (k6’s load-shape model), thresholds and checks in depth, and cloud/CI integration.

Takeaway: k6’s biggest practical advantage isn’t a performance benchmark win over other tools — it’s that a load test script becomes an ordinary, reviewable file in your codebase, which changes how naturally performance testing fits into a normal development workflow.

Discussions coming soon.

Comments are powered by Giscus (GitHub Discussions). Enable them by configuring GISCUS in src/consts.ts — see giscus.app.