Skip to main content
The mizu dev command runs your Mizu application in development mode. It automatically finds your main package, compiles your code, starts your server, and handles shutdown gracefully when you press Ctrl+C. This is the command you’ll use most during development.

Basic Usage

That’s it! The command auto-detects your main package and runs it.

What Happens When You Run mizu dev

  1. Finds your main package - Looks in cmd/ folder first, then checks the root directory
  2. Compiles your code - Uses go run to build and run
  3. Starts your server - Your application starts running
  4. Waits for shutdown - Listens for Ctrl+C or system signals
  5. Shuts down gracefully - Gives your app time to clean up before exiting
Example output:
Your server is now running! Open your browser to http://localhost:8080 to see it.

How to Stop the Server

Press Ctrl+C in your terminal. You’ll see:
The CLI sends a signal to your application, giving it time to:
  • Close database connections
  • Finish processing requests
  • Save any pending data
If your app doesn’t stop within 15 seconds, it’s force-terminated.

Flags Reference

How Main Package Discovery Works

The CLI finds your main package automatically. Here’s the order it checks:

1. If You Specify --cmd

Uses exactly what you specify. No auto-detection.

2. Look in cmd/ Directory

If you have a cmd/ folder, the CLI looks for main.go files inside subdirectories:

3. Check Root Directory

If there’s no cmd/ folder, it checks the current directory:

When Discovery Fails

If no main package is found:
Fix: Either:
  • Create a cmd/<name>/main.go file
  • Create a main.go in your root directory
  • Use --cmd to point to your main package

Working with Multiple Commands

If your project has multiple entry points:
You need to specify which one to run:

Passing Arguments to Your Application

Use -- to separate CLI flags from your application’s arguments:
Everything after -- is passed to your application. Your app will receive --port 9000 --debug as arguments.

JSON Output Mode

For scripts and automation, use --json to get machine-readable output:
This outputs one JSON object per line (NDJSON format):

Lifecycle Events

Event Structure

  • event - Type of event
  • timestamp - When it happened (UTC, ISO 8601 format)
  • message - Human-readable description
  • exit_code - Only included when application exits

Verbose Mode

See more details about what’s happening:
Output:

Error Messages and Solutions

No Main Package Found

Why: The CLI couldn’t find a package main in your project. Fix:
  1. Make sure you’re in the right directory
  2. Check that your main.go file has package main at the top
  3. Use --cmd to specify the path manually

Path Does Not Exist

Why: You specified a --cmd path that doesn’t exist. Fix: Check the path and make sure it’s correct.

Build Errors

If your Go code has errors, you’ll see the compiler output:
Fix: Fix the Go compilation errors shown.

Exit Codes

The exit code from your application passes through mizu dev:
If your app exits with code 5, mizu dev also exits with code 5. This is important for scripts that check exit codes.

Development Workflow

A typical development workflow:
mizu dev does not watch for file changes. When you modify your code, stop the server with Ctrl+C and restart it.
For the best experience with mizu dev, use this structure:
With this structure:
  • mizu dev finds ./cmd/api automatically
  • Code is organized by feature
  • Clear separation of concerns

Using with Scripts

Check if the server started successfully:

Common Questions

Why doesn’t mizu dev watch for file changes?

File watching adds complexity and dependencies. For now, just restart manually. Many editors have built-in run commands that make this easy.

Can I run multiple servers at once?

Yes! Open multiple terminals:

How do I change the port?

Configure the port in your application code or use arguments:
(Your application needs to handle the --port flag)

Next Steps

Create a Project

Start a new project with mizu new

View Templates

See what templates are available