> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/grafana/k6/llms.txt
> Use this file to discover all available pages before exploring further.

# k6 new

> Create a new k6 test script from a template

# k6 new

Create and initialize a new k6 script using one of the predefined templates.

## Synopsis

```bash theme={null}
k6 new [flags] [file]
```

## Description

The `k6 new` command creates a new test script from a template. By default, it creates a file named `script.js` unless a different filename is specified.

This command helps you quickly get started with k6 by providing pre-configured templates for common testing scenarios.

## Arguments

<ParamField path="file" type="string" default="script.js">
  The name of the script file to create
</ParamField>

## Examples

```bash theme={null}
# Create a new k6 script with the default template
k6 new

# Specify a file name when creating a script
k6 new test.js

# Overwrite an existing file
k6 new -f test.js

# Create a script using a specific template
k6 new --template protocol

# Create a cloud-ready script with a specific project ID
k6 new --project-id 12315
```

## Flags

<ParamField path="-f, --force" type="boolean">
  Overwrite existing files without prompting
</ParamField>

<ParamField path="--template" type="string" default="minimal">
  Template type to use. Available options:

  * `minimal` - Basic k6 test script
  * `protocol` - Protocol-level testing template
  * `browser` - Browser automation template
  * Path to a custom template file (relative or absolute)
</ParamField>

<ParamField path="--project-id" type="string">
  Specify the Grafana Cloud project ID for the test. This pre-configures the script for cloud execution.
</ParamField>

## Template Types

### minimal

The minimal template creates a simple load test with basic HTTP requests. This is ideal for getting started quickly.

### protocol

The protocol template includes examples of various HTTP methods, request configuration, and response validation.

### browser

The browser template sets up a browser-based test using k6's browser testing capabilities.

### Custom Templates

You can also provide a path to your own custom template file:

```bash theme={null}
k6 new --template ./templates/my-template.js my-test.js
```

## Output

When successful, the command outputs:

```
New script created: <filename> (<template> template).
```

## Error Handling

The command will fail if:

* The target file already exists and `--force` is not specified
* The specified template doesn't exist or is invalid
* There are file system permission issues

## See Also

* [k6 run](/cli/run) - Run your newly created test
* [k6 cloud](/cli/cloud) - Run tests in Grafana Cloud
