Features
Docs
CLI
Benchmarks
Examples

© 2024 MoroJs

Deployment Overview

Deploy your MoroJS API anywhere. Step-by-step guides for each platform, quick reference tables, and troubleshooting tips.

What You'll Learn

  • How to deploy to different runtime environments
  • Platform-specific configuration and optimizations
  • Runtime comparison and performance characteristics
  • Common deployment patterns and best practices
1

Choose Your Runtime

2

Write Universal Code

Write your API once. It works on all platforms:

src/server.ts - Works everywhere

typescript

1import { createApp } from '@morojs/moro';
2
3const app = createApp();
4
5app.get('/api/hello', () => {
6  return { 
7    message: 'Hello from MoroJS!',
8    runtime: process.env.RUNTIME || 'node',
9    timestamp: new Date().toISOString()
10  };
11});
12
13// For Node.js
14if (process.env.RUNTIME === 'node') {
15  app.listen(3000);
16}
17
18// For serverless/edge - export the handler
19export default app;

✓ What this does: Creates a universal API that works on Node.js, Vercel, Lambda, and Cloudflare Workers.

Runtime Comparison

RuntimeCold StartThroughputBest For
Node.js~200ms136k+ req/secAPIs, WebSockets, File processing
Vercel Edge~50ms45k+ req/secGlobal APIs, CDN integration
AWS Lambda~300ms40k+ req/secEvent processing, AWS integration
Cloudflare Workers~10ms50k+ req/secEdge computing, Global distribution

Common Deployment Patterns

Vercel Deployment

vercel.json

typescript

1{
2  "functions": {
3    "api/[...route].ts": {
4      "runtime": "@vercel/node"
5    }
6  }
7}

api/[...route].ts

typescript

1import { createApp } from '@morojs/moro';
2import { createVercelAdapter } from '@morojs/vercel';
3
4const app = createApp();
5// Your routes...
6
7export default createVercelAdapter(app);

Docker Deployment

Dockerfile

typescript

1FROM node:24-alpine
2WORKDIR /app
3COPY package*.json ./
4RUN npm ci --only=production
5COPY . .
6RUN npm run build
7EXPOSE 3000
8CMD ["npm", "start"]

Troubleshooting

Common Issues

  • Cold start delays: Use edge runtimes (Vercel Edge, Cloudflare Workers) for faster cold starts
  • Environment variables: Ensure all required env vars are set in your deployment platform
  • File system access: Some runtimes (Lambda, Workers) have limited file system access
  • WebSocket support: Only Node.js runtime supports WebSockets natively

Best Practices

  • Use environment variables for configuration
  • Test locally before deploying
  • Monitor cold start times and optimize
  • Use platform-specific adapters for optimal performance

Choose Your Runtime