---
title: "Write your first k6 test script | Grafana Labs"
description: "Create a k6 test script that performs HTTP requests and measures response times."
---

> For a curated documentation index, see [llms.txt](/llms.txt). For the complete documentation index, see [llms-full.txt](/llms-full.txt).

# Write your first k6 test script

Create a small k6 script that calls QuickPizza, checks the response, and pauses between iterations. The next milestone runs it locally.

## Generate a test script with `k6 new`

Use `k6 new` to create a starter script.

Run the following command in a directory on your machine (for example, a new folder for this journey, or any existing project):

Bash ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy

```bash
k6 new script.js
```

This creates `script.js` in the current directory. You can use another name, but keep the `.js` or `.ts` extension.

> Tip
> 
> `k6 new` supports different templates for different use cases. The default `minimal` template is a great starting point. To learn more, refer to [Create a test script using the CLI](/docs/k6/latest/using-k6/test-authoring/create-test-script-using-the-cli/).

## Customize the script

Open `script.js` in your code editor and replace the contents with:

JavaScript ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy

```javascript
import http from 'k6/http';
import { check, sleep } from 'k6';

export const options = {
  iterations: 10,
};

export default function () {
  const res = http.get('https://quickpizza.grafana.com');
  check(res, { 'status was 200': (r) => r.status === 200 });
  sleep(1);
}
```

Save the file. The script has three parts:

- **Imports**: The `http` module enables you to make HTTP requests, while `check` validates responses and `sleep` introduces delays between iterations to simulate real-world usage.
- **Options**: The `iterations: 10` configuration tells k6 to execute the default function 10 times.
- **Default function**: This is the entry point for your test. Each iteration sends a GET request to the [QuickPizza demo app](https://quickpizza.grafana.com), verifies the response status is 200, and then pauses for 1 second.

If you encounter script issues, refer to the [k6 documentation on writing tests](/docs/k6/latest/get-started/write-your-first-test/).

In the next milestone, you’ll run this test script locally to see k6 in action and view the test results.
