Deployment
Node.js Deployment
Deploy your MoroJS applications to Node.js servers with full feature support including WebSockets, file system access, and database connections.
Basic Deployment
Production Servertypescript
1import { createApp } from '@morojs/moro';
2
3const app = await createApp({
4 server: {
5 port: process.env.PORT || 3000,
6 host: process.env.HOST || '0.0.0.0'
7 }
8});
9
10// Your routes here
11app.get('/health', () => ({ status: 'healthy' }));
12
13// Start server
14const server = app.listen();
15
16// Graceful shutdown
17process.on('SIGTERM', async () => {
18 console.log('Shutting down gracefully...');
19 await app.close();
20 process.exit(0);
21});
22
23process.on('SIGINT', async () => {
24 console.log('Shutting down gracefully...');
25 await app.close();
26 process.exit(0);
27});package.json Scriptstypescript
1{
2 "scripts": {
3 "dev": "tsx watch src/server.ts",
4 "build": "tsc",
5 "start": "NODE_ENV=production node dist/server.js",
6 "test": "jest",
7 "lint": "eslint src/**/*.ts"
8 }
9}Environment Configuration
.env.productiontypescript
1NODE_ENV=production
2PORT=3000
3HOST=0.0.0.0
4
5# Database
6DATABASE_URL=postgresql://user:pass@localhost:5432/myapp
7
8# Security
9JWT_SECRET=your-super-secret-jwt-key
10API_KEY_SECRET=your-api-key-secret
11
12# External services
13REDIS_URL=redis://localhost:6379
14SMTP_URL=smtp://user:pass@smtp.example.com:587
15
16# Logging
17LOG_LEVEL=info
18LOG_FORMAT=json
19
20# Rate limiting
21RATE_LIMIT_MAX=1000
22RATE_LIMIT_WINDOW=1hEnvironment Loadingtypescript
1import { createApp } from '@morojs/moro';
2import dotenv from 'dotenv';
3
4// Load environment variables
5dotenv.config();
6
7const app = await createApp({
8 server: {
9 port: parseInt(process.env.PORT || '3000'),
10 host: process.env.HOST || 'localhost'
11 },
12 database: {
13 url: process.env.DATABASE_URL
14 },
15 redis: {
16 url: process.env.REDIS_URL
17 },
18 logging: {
19 level: process.env.LOG_LEVEL || 'info',
20 format: process.env.LOG_FORMAT || 'pretty'
21 }
22});Docker Deployment
Dockerfiletypescript
1FROM node:24-alpine
2
3# Create app directory
4WORKDIR /usr/src/app
5
6# Copy package files
7COPY package*.json ./
8
9# Install dependencies
10RUN npm ci --only=production
11
12# Copy source code
13COPY . .
14
15# Build the application
16RUN npm run build
17
18# Create non-root user
19RUN addgroup -g 1001 -S nodejs
20RUN adduser -S moro -u 1001
21
22# Change ownership
23RUN chown -R moro:nodejs /usr/src/app
24USER moro
25
26# Expose port
27EXPOSE 3000
28
29# Health check
30HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
31 CMD node healthcheck.js
32
33# Start the application
34CMD ["npm", "start"]docker-compose.ymltypescript
1version: '3.8'
2
3services:
4 app:
5 build: .
6 ports:
7 - "3000:3000"
8 environment:
9 - NODE_ENV=production
10 - DATABASE_URL=postgresql://postgres:password@db:5432/myapp
11 - REDIS_URL=redis://redis:6379
12 depends_on:
13 - db
14 - redis
15 restart: unless-stopped
16
17 db:
18 image: postgres:15-alpine
19 environment:
20 POSTGRES_DB: myapp
21 POSTGRES_USER: postgres
22 POSTGRES_PASSWORD: password
23 volumes:
24 - postgres_data:/var/lib/postgresql/data
25 restart: unless-stopped
26
27 redis:
28 image: redis:7-alpine
29 restart: unless-stopped
30
31volumes:
32 postgres_data: