Deployment
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
Choose Your Runtime
MoroJS works across multiple runtime environments. Choose based on your needs:
Node.js
Traditional server deployment with full feature support
Vercel Edge
Ultra-fast edge runtime for global distribution
AWS Lambda
Serverless deployment with AWS ecosystem integration
Cloudflare Workers
Edge computing with global distribution
Tip: Your code works the same across all platforms. MoroJS automatically adapts to each runtime.
Write Universal Code
Write your API once. It works on all platforms:
src/server.ts - Works everywheretypescript
1import { createApp } from '@morojs/moro';
2
3const app = await 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
| Runtime | Cold Start | Throughput | Best For |
|---|---|---|---|
| Node.js | ~200ms | 740k+ req/sec | APIs, WebSockets, File processing |
| Vercel Edge | ~50ms | 45k+ req/sec | Global APIs, CDN integration |
| AWS Lambda | ~300ms | 40k+ req/sec | Event processing, AWS integration |
| Cloudflare Workers | ~10ms | 50k+ req/sec | Edge computing, Global distribution |
Common Deployment Patterns
Vercel Deployment
vercel.jsontypescript
1{
2 "functions": {
3 "api/[...route].ts": {
4 "runtime": "@vercel/node"
5 }
6 }
7}api/[...route].tstypescript
1import { createApp } from '@morojs/moro';
2import { createVercelAdapter } from '@morojs/vercel';
3
4const app = await createApp();
5// Your routes...
6
7export default createVercelAdapter(app);Docker Deployment
Dockerfiletypescript
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