0
k6 is an open-source load testing tool designed for developer happiness and performance testing in CLI environments. It uses JavaScript to define test scenarios.
How to write and run an API load test using k6 CLI?
Follow these steps to execute a performance test from the terminal:
1. Create a Test Script (script.js)
import http from 'k6/http';
import { check, sleep } from 'k6';
export const options = {
vus: 10,
duration: '30s',
};
export default function () {
const res = http.get('https://api.example.com/v1/health');
check(res, {
'status is 200': (r) => r.status === 200,
});
sleep(1);
}2. Execute via Command Prompt
k6 run script.jsThe CLI output displays real-time metrics including HTTP request duration, failure rate, and request volume per second.