Skip to content

Development Server

The pidgn server command (also available as pidgn s) starts a development server that builds and runs your application, then watches for changes and automatically restarts when source files are modified.

Terminal window
pidgn server

The server performs the following cycle:

  1. Runs zig build run to compile and start your application.
  2. Prints “Server running. Watching for changes…” when the build succeeds.
  3. When the process exits (due to a file change trigger or an error), it rebuilds and restarts.
  4. Press Ctrl+C to stop.
  1. Navigate to your pidgn project directory:

    Terminal window
    cd my_app
  2. Start the development server:

    Terminal window
    pidgn server
  3. Open http://127.0.0.1:4000 in your browser.

  4. Edit any .zig file under src/ — the server will rebuild and restart automatically.

Starting pidgn development server...
Building...
Server running. Watching for changes... (Ctrl+C to stop)

If the build fails or the server exits with a non-zero code, the CLI waits two seconds before retrying:

Server exited with code 1. Waiting for changes to retry...
Building...

A clean exit (code 0) or a termination signal (e.g., Ctrl+C) stops the loop entirely.

The dev server uses zig build run, which loads config/dev.zig by default. To run with a different environment configuration, use zig build run directly with the -Denv flag:

Terminal window
zig build run -Denv=staging

A typical development session looks like this:

  1. Start the dev server:

    Terminal window
    pidgn server
  2. Generate new code as needed:

    Terminal window
    # In another terminal:
    pidgn gen controller Products
    pidgn gen model Product name:string price:float in_stock:boolean
    pidgn migrate
  3. Edit the generated files to add your application logic.

  4. The dev server detects the changes and rebuilds automatically.

  5. Test your endpoints in the browser or with curl:

    Terminal window
    curl http://127.0.0.1:4000/products

In a separate terminal, use the test command to run your project’s test suite at any time:

Terminal window
pidgn test

This invokes zig build test and reports the results.

To see all routes defined in your application:

Terminal window
pidgn routes

This runs your app with the --routes flag, which prints a formatted table of all registered routes, their HTTP methods, and handler functions.

For instant browser refresh during development, combine pidgn server with live reload. The dev server handles Zig rebuilds, while live reload pushes changes to the browser over a WebSocket.

If your project uses the asset pipeline, run pidgn assets watch in a separate terminal alongside the dev server so that CSS and JavaScript changes are also picked up:

Terminal window
# Terminal 1: Zig source rebuilds
pidgn server
# Terminal 2: asset rebuilds
pidgn assets watch