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 to shut it down when done.

Example

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

template.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:

npx croct@latest use template.json5

Properties

These are the supported properties:

name
string

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

server(optional)
object

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(optional)
Array<string>

Additional arguments to pass to the script.

result(optional)
object

Variable names to store the server information.

id(optional)
string

The variable name to store the server ID.

Use this ID with stop-server to shut down the server. The value is null if the server was already running before this action.

url(optional)
string

The variable name to store the server URL.