#Dev Command
Start your development server with a single command. Hot reloading, fast refresh, environment variables - it all just works.
#Quick Start
alepha dev
That's it. Your app is running. Make changes and watch them appear instantly.
#Options
| Flag | Description |
|---|---|
--only |
Run only specific apps in a monorepo (comma-separated: --only api,web) |
--port |
The port to serve on, ahead of SERVER_PORT and dev.port. 0 takes any free port. In a monorepo, the first app's port |
--mode, -m |
Also load .env.<mode> and .env.<mode>.local. In workspace mode it is forwarded to every app |
#What It Does
The dev command runs your app through a Vite dev server:
alepha dev
# → http://localhost:5173 (the default when no port is configured)
#Port
The port is resolved in this order: the --port flag, then the SERVER_PORT environment variable, then dev.port in alepha.config.ts, then Vite's server.port, then 5173. The chosen port is bound strictly - a second dev server on the same port fails loudly instead of drifting to 5174:
1export default defineConfig({2 dev: { port: 3303 },3});
#Without a terminal
A script, a CI job or a coding agent usually starts alepha dev in the background with its output going to a file. When there is no terminal, a first boot that fails (a syntax error, a missing module) exits with code 1 and one line, alepha dev: failed reason="...", instead of waiting for a file save that nobody will make. Pass --retry to keep waiting anyway. In a terminal, dev still waits for the fix and reloads.
When a missing module is one of the app's own workspace: dependencies that is not linked into node_modules, the error says so and tells you to run the install again.
Once the server listens, it prints one plain line to wait for, instead of polling the port:
alepha dev --port 0 > dev.log 2>&1 &
grep -m1 "alepha dev: " <(tail -f dev.log)
# alepha dev: ready url=http://localhost:54012/ pid=4242
--port 0 (or SERVER_PORT=0) takes any free port, so two servers started at once never collide, and the app reads the real port rather than 0. The same facts are in node_modules/.alepha/dev.json (status, url, port, pid, and reason after a failure), which is deleted when the server stops. Colours are left out whenever the output is not a terminal; FORCE_COLOR=1 brings them back.
The page's console.error and console.warn calls and its uncaught errors are printed in the dev server's output too, with source-mapped stacks, so a broken page shows up in the same log as the server. Vite does this by itself when it recognises a coding agent; without a terminal, dev turns it on for any caller.
You get:
- Hot Module Replacement: Changes appear instantly without full page reload
- Fast Refresh: React state preserved during edits
- SSR in development: Same rendering behavior as production
- Source maps: Debug your actual TypeScript code
Backend-only projects (no browser entry) run through the same Vite server - you still get instant reload on save, without a bundler/watcher setup of your own.
React Fast Refresh comes from Vite's React plugin, which dev registers for you. Set dev.noViteReactPlugin: true in alepha.config.ts to leave it out.
#Inspector
alepha dev mounts alepha/inspector into the app on every load, so alepha mcp can see it. No app imports the inspector itself: a production build carries it only when built with alepha build --inspect.
#Workspace Mode
Run alepha dev from a workspace root with an apps/ directory, and it spawns every app in parallel:
alepha dev
# → api http://localhost:5173
# → web http://localhost:5174
- Each app gets a port from its position in the
apps/listing, starting at 5173, or at--portwhen given (--port 0gives every app a free port of its own). Ports are stable:--only webkeepswebon the same port it has when all apps run, so OAuth redirect URIs and client configs stay valid. - Each app runs with
SERVER_PORTset to that port andAPP_NAMEset to its name in upper case, which prefixes its log lines. --only api,webfilters which apps start, and--modeis forwarded to every app.- Scoped directories (
apps/@myorg/api) are supported.
#Entry Point Detection
Alepha looks for your server entry under src/, in this order:
src/main.server.ts(or.tsx)src/main.ts(or.tsx)
The browser entry is optional and resolved the same way: src/main.browser.ts(x), then src/main.ts(x). A stylesheet is picked up from src/main.css, src/styles.css, or src/style.css.
You can override any of these in alepha.config.ts:
1import { defineConfig } from "alepha/cli/config";2 3export default defineConfig({4 entry: {5 server: "src/server.ts",6 browser: "src/client.ts",7 style: "src/theme.css",8 },9});
Entry Point Required
If no server entry is found, the command fails with the list of paths it tried.
#Environment Variables
Automatic .env Loading
The
devcommand automatically loads.envfiles - no extra setup required.On a fresh clone there is no
.env, since it is gitignored. When the project has a.env.example,devfirst copies it to.env(readable by its owner only) and says so. It never overwrites an existing.env, and leaves.env.localand.env.<mode>alone.
Environment variables from .env are available immediately:
DATABASE_URL=postgres://localhost/mydb
API_KEY=secret123
These are available in your code via process.env or the $env primitive:
1import { $env, z } from "alepha"; 2 3class MyService { 4 protected readonly env = $env( 5 z.object({ 6 DATABASE_URL: z.text(), 7 API_KEY: z.text(), 8 }), 9 );10 11 connect() {12 console.log(this.env.DATABASE_URL);13 }14}
#Vite Integration
Under the hood, the dev server is Vite, fully configured by the Alepha CLI:
- React Fast Refresh: Edit components without losing state
- Server-Side Rendering: Your pages render on the server during development
- API Routes: Define
$actionendpoints that work seamlessly - Static Assets: Import images, fonts, and other assets directly
Your vite.config.ts stays minimal because the CLI does the heavy lifting - the file exists so extra Vite plugins (like Tailwind) can hook in, and so Vitest has its test block:
1import tailwindcss from "@tailwindcss/vite"; 2import { defineConfig } from "vitest/config"; 3 4export default defineConfig({ 5 plugins: [tailwindcss()], 6 test: { 7 root: ".", 8 globals: true, 9 },10});
#Debugging
#Server-Side Code
Your server code runs in Node.js. Use standard debugging - --inspect on the CLI process, or VS Code's debugger with a launch.json config.
#Client-Side Code
Open browser DevTools. Your TypeScript source maps are there.
#Logs
Alepha's logger writes to the console during development. Control verbosity with environment variables:
LOG_LEVEL=debug alepha dev # More details
LOG_LEVEL=trace alepha dev # Everything
#Auto-Configuration
The first time you run dev, Alepha creates a tsconfig.json if it's missing. This means you can literally start with just a src/main.ts file:
1// src/main.ts2import { Alepha } from "alepha";3 4const alepha = Alepha.create();5await alepha.start();
Zero Config Start
You don't need to run
alepha initfirst - just start coding.initgives you the full scaffold;devonly needs an entry file.
#Tips
Keep the terminal visible. Errors and logs appear there. It's your feedback loop.
Trust your IDE. Let your editor show type errors as you code. When you're done, run alepha verify to catch everything at once.
Trust the hot reload. If something looks wrong, try a hard refresh (Cmd+Shift+R). If that doesn't help, restart the dev server.
Check network tab. For API debugging, the browser's network tab shows all requests to your $action endpoints.