Using CLI

Use the srvx CLI command to easily start a development or production server.

You can run srvx with your preferred runtime without installation:

npx srvx

Usage

srvx - Start an HTTP server with the specified entry path.

USAGE

// server.ts
export default {
  fetch(req: Request) {
    return new Response("Hello, World!");
  }
}

# srvx [options] [entry]
$ srvx ./server.ts            # Start development server
$ srvx --prod                 # Start production  server
$ srvx --port=8080            # Listen on port 8080
$ srvx --host=localhost       # Bind to localhost only
$ srvx --import=jiti/register # Enable [jiti](https://github.com/unjs/jiti) loader
$ srvx --tls --cert=cert.pem --key=key.pem  # Enable TLS (HTTPS/HTTP2)

FETCH MODE

# srvx fetch [options] [url]
$ srvx fetch                  # Fetch from default entry
$ srvx fetch /api/users       # Fetch a specific URL/path
$ srvx fetch --entry ./server.ts /api/users # Fetch using a specific entry
$ srvx fetch -X POST /api/users # POST request
$ srvx fetch -H "Content-Type: application/json" /api # With headers
$ srvx fetch -d '{"name":"foo"}' /api # With request body
$ echo '{"name":"foo"}' | srvx fetch -d @- /api # Body from stdin
$ srvx fetch -v /api/users    # Verbose output (show headers)

ARGUMENTS

  <entry>                  Server entry path to serve.
                           Default: server, index, src/server, src/index, server/index (.mts,.ts,.cts,.js,.mjs,.cjs,.jsx,.tsx)

OPTIONS

  -p, --port <port>        Port to listen on (default: 3000)
  --host <host>            Host to bind to (default: all interfaces)
  -s, --static <dir>       Serve static files from the specified directory (default: public)
  --prod                   Run in production mode (no watch, no debug)
  --import <loader>        ES module to preload
  --tls                    Enable TLS (HTTPS/HTTP2)
  --cert <file>            TLS certificate file
  --key  <file>            TLS private key file
  -h, --help               Show this help message
  --version                Show server and runtime versions

FETCH OPTIONS

  -X, --request <method>   HTTP method (default: GET, or POST if body is provided)
  -H, --header <header>    Add header (format: "Name: Value", can be used multiple times)
  -d, --data <data>        Request body (use @- for stdin, @file for file)
  -v, --verbose            Show request and response headers

ENVIRONMENT

  PORT                     Override port
  HOST                     Override host
  NODE_ENV                 Set to production for production mode.

 [Documentation](https://srvx.h3.dev)
 [Report issues](https://github.com/h3js/srvx/issues)