Quick Start

Get up and running with MoroJS in minutes. This guide will walk you through creating your first high-performance API.

Prerequisites

  • Node.js 18+ installed
  • Basic TypeScript knowledge
  • Package manager (npm, yarn, or pnpm)

1. Installation

ESM-Only Framework

MoroJS is built for modern JavaScript and requires ESM (ES Modules). Make sure your project uses "type": "module" in package.json and proper TypeScript configuration for ESM support.

npm

bash

1npm install @morojs/moro

yarn

bash

1yarn add @morojs/moro

pnpm

bash

1pnpm add @morojs/moro

Create Your Project

bash

1# Create a new project
2mkdir my-moro-api && cd my-moro-api
3
4# Initialize package.json
5npm init -y && \
6npm pkg set type=module scripts.dev="tsx watch src/server.ts" scripts.build="tsc" scripts.start="node dist/server.js" && \
7npm install -D tsx typescript @types/node && \
8npm install @morojs/moro
9
10# Create tsconfig.json (ESM configuration)
11cat > tsconfig.json << 'EOF'
12{
13  "compilerOptions": {
14    "target": "ES2022",
15    "module": "NodeNext",
16    "moduleResolution": "NodeNext",
17    "esModuleInterop": true,
18    "allowSyntheticDefaultImports": true,
19    "strict": true,
20    "skipLibCheck": true,
21    "forceConsistentCasingInFileNames": true,
22    "outDir": "./dist",
23    "rootDir": "./src"
24  },
25  "include": ["src/**/*"],
26  "exclude": ["node_modules", "dist"]
27}
28EOF

2. Your First API

src/server.ts

typescript

1import { createApp } from '@morojs/moro';
2
3// Create a new MoroJS application
4const app = createApp({
5  server: {
6    port: 3000,
7    host: '0.0.0.0',
8  },
9});
10
11// Define a simple route
12app.get('/').handler(() => {
13  return { 
14    message: 'Hello from MoroJS!',
15    timestamp: new Date().toISOString(),
16    version: '1.0.0'
17  };
18});
19
20// Add a parameterized route
21app.get('/users/:id').handler(({ params }) => {
22  return {
23    userId: params.id,
24    message: `User ${params.id} retrieved successfully`
25  };
26});
27
28// Start the server
29await app.listen(() => {
30  const config = app.getConfig();
31  console.log(
32    `🚀 MoroJS running on http://localhost:${config.server.port}`
33  );
34});

3. Run Your API

Start Development Server

bash

1# Start development server with hot reload
2npm run dev

Test Your API

Your API is now running! Try these endpoints:

  • GET http://localhost:3000/
  • GET http://localhost:3000/users/123

4. Adding Type-Safe Validation

MoroJS includes built-in Zod validation for type-safe request handling:

src/server.ts - With Validation

typescript

1import { Moro, z } from '@morojs/moro';
2
3const app = new Moro({
4  server: {
5    port: 3000,
6    host: '0.0.0.0',
7  },
8});
9
10// Define validation schemas
11const CreateUserSchema = z.object({
12  name: z.string().min(1),
13  email: z.string().email(),
14  age: z.number().min(18).max(120)
15});
16
17const UserParamsSchema = z.object({
18  id: z.string().uuid()
19});
20
21// GET route with param validation - Chainable API
22app.get('/users/:id')
23  .params(UserParamsSchema)
24  .handler(({ params }) => {
25    // params.id is now type-safe and validated
26    return {
27      userId: params.id,
28      message: `User ${params.id} retrieved successfully`
29    };
30  });
31
32// POST route with body validation - Chainable API
33app.post('/users')
34  .body(CreateUserSchema)
35  .handler(({ body }) => {
36    // body is now type-safe and validated
37    return {
38      message: 'User created successfully',
39      user: {
40        id: crypto.randomUUID(),
41        ...body,
42        createdAt: new Date().toISOString()
43      }
44    };
45  });
46
47await app.listen(() => {
48  const config = app.getConfig();
49  console.log(
50    `🚀 MoroJS running on http://localhost:${config.server.port}`
51  );
52});

5. Level Up with MoroJS CLI

Ready for more advanced features? The MoroJS CLI can help you build production-ready applications with enterprise features, database integration, and automated deployment.

Quick Project Setup

Generate a full project

bash

1# Install CLI
2npm install -g @morojs/cli
3
4# Create enterprise-ready project
5morojs-cli init my-enterprise-api \
6  --runtime=node \
7  --database=postgresql \
8  --features=auth,cors,docs

Add Advanced Modules

Generate complete modules

bash

1# Create user management module
2morojs-cli module create users \
3  --features=auth,database,validation \
4  --with-tests
5
6# Add database setup
7morojs-cli db setup postgresql

What You Get

Project Scaffolding
  • • TypeScript configuration
  • • Database adapters
  • • Authentication setup
  • • Testing framework
Advanced Features
  • • Module generation
  • • Database migrations
  • • Security scanning
  • • API documentation
Deployment
  • • Multi-runtime support
  • • Automated deployment
  • • Configuration management
  • • Production optimization

Next Steps

Performance Tip

Your API is already optimized for production! MoroJS delivers 68k+ req/sec out of the box. For production deployment, make sure to:

  • Set NODE_ENV=production
  • Enable compression middleware
  • Configure appropriate logging levels