Getting Started
Quick Start
One command scaffolds a typed, validated MoroJS API. You'll have a running server in under a minute.
What You'll Learn
- Scaffold a MoroJS project with the CLI
- Run the dev server and hit your first endpoints
- Add a typed, validated route
Scaffold Your Project
Run the CLI. You'll be prompted for runtime, validation library, and optional features. Press enter to accept the defaults for a typed REST API.
1npx @morojs/cli init my-apiWhat this does: Creates my-api/ with TypeScript, ESM, validation, and a working src/index.ts wired up. The CLI auto-detects your package manager and installs dependencies.
Want a full project, not just a basic API? The Interactive Project Builder lets you pick a database, auth, runtime, validation, and features, then copies the exact init command to scaffold it all.
Run It
Start the dev server with hot reload:
1cd my-api
2npm run devYou'll see the server come up on port 3000. Hit the welcome and health endpoints already scaffolded for you:
GET http://localhost:3000/: welcome endpointGET http://localhost:3000/health: health check
Add a Typed, Validated Route
Open src/index.ts and add a parameterized GET and a validated POST. Save, and the dev server reloads automatically.
1import { z } from 'zod';
2
3// Parameterized route — req.params.id is typed as string
4app.get('/users/:id').handler((req) => {
5 return {
6 userId: req.params.id,
7 message: `User ${req.params.id} retrieved`,
8 };
9});
10
11// POST route with body validation (chainable pattern)
12const CreateUserSchema = z.object({
13 name: z.string().min(1),
14 email: z.string().email(),
15 age: z.number().min(18).max(120),
16});
17
18app.post('/users')
19 .validate({ body: CreateUserSchema })
20 .handler((req) => {
21 // req.body is fully typed and validated
22 return {
23 message: 'User created',
24 user: {
25 id: crypto.randomUUID(),
26 ...req.body,
27 createdAt: new Date().toISOString(),
28 },
29 };
30 });Result: TypeScript knows the shape of req.body from the Zod schema. Invalid requests are rejected automatically before your handler runs.
Prefer to set up MoroJS by hand instead of using the CLI?