# start-server

Learn how to start a development server.

This action starts a development server and waits until it is ready before continuing to the next action.

When no configuration is provided, the action auto-detects the server script and URL from the project. Use [`stop-server`](/reference/cli/templates/actions/stop-server) to shut it down when done.

## Example

The following template starts the server and opens it in the browser:

**template.json5**

```json5
{
  "$schema": "https://schema.croct.com/json/v1/template.json",
  "title": "Live preview",
  "description": "Starts the server and opens a preview.",
  "actions": [
    {
      "name": "install"
    },
    {
      "name": "start-server",
      "server": {
        "script": "dev",
        "url": "http://localhost:3000"
      },
      "result": {
        "id": "serverId",
        "url": "serverUrl"
      }
    },
    {
      "name": "open-link",
      "url": "${this.serverUrl}"
    },
    {
      "name": "prompt",
      "type": "keypress",
      "message": "Press any key to stop the server"
    },
    {
      "name": "stop-server",
      "id": "${this.serverId}"
    }
  ]
}
```

To apply this template, run:

```sh
croct use template.json5
```

## Properties

These are the supported properties:

- `name`: `string`

  The action identifier. Always `start-server` for this action.

- `server`: `object` (optional)

  The server configuration.

  When omitted, the action auto-detects the script and URL from the project's configuration.

  - `script`: `string`

    The name of the script to run.

  - `url`: `string`

    The URL to wait for before continuing.

    The action polls this URL until the server responds, then proceeds to the next action.

  - `arguments`: `Array<string>` (optional)

    Additional arguments to pass to the script.

- `result`: `object` (optional)

  Variable names to store the server information.

  - `id`: `string` (optional)

    The variable name to store the server ID.

    Use this ID with [`stop-server`](/reference/cli/templates/actions/stop-server) to shut down the server. The value is `null` if the server was already running before this action.

  - `url`: `string` (optional)

    The variable name to store the server URL.

## Explore

- [Stop server](/reference/cli/templates/actions/stop-server): Learn how to stop the development server.
- [Install](/reference/cli/templates/actions/install): Learn how to install dependencies before starting.
