Copy-and-run k6 example code. Get started quickly with real-world flows, from Load, Stress, and Spike scenarios to CI/CD automation.
Main run command: k6 run script.js
After installing k6, move the target URL into an environment variable.
export BASE_URL=https://staging.example.com
k6 versionRamp up to the expected everyday traffic in stages and hold it.
export const options = { stages: [{ duration: '2m', target: 50 }, { duration: '5m', target: 50 }, { duration: '1m', target: 0 }] };Use response time and failure rate as the CI pass criteria.
thresholds: { http_req_duration: ['p(95)<500'], http_req_failed: ['rate<0.01'] }Check for performance regressions on every PR and keep the results as artifacts.
npm install -g k6
k6 run --out json=results.json tests/load.jsWhen adapting an example to a real service, first separate out the URL, credentials, thresholds, and report output location.
Go to the guide →