Deployment
Deployment Options
Section titled “Deployment Options”NexaSpace applications can be deployed to any cloud platform or on-premises infrastructure.
Docker Deployment
Section titled “Docker Deployment”Dockerfile
Section titled “Dockerfile”Create a Dockerfile in your project root:
FROM node:20-alpine
WORKDIR /app
# Copy package filesCOPY package*.json ./
# Install dependenciesRUN npm ci --only=production
# Copy source codeCOPY . .
# Build applicationRUN npm run build
# Expose portEXPOSE 3000
# Health checkHEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \ CMD node healthcheck.js
# Start applicationCMD ["npm", "start"]Docker Compose
Section titled “Docker Compose”For multi-service deployments:
version: '3.8'
services: app: build: . ports: - "3000:3000" environment: - NODE_ENV=production - DATABASE_URL=postgresql://db:5432/nexaspace depends_on: - db restart: unless-stopped
db: image: postgres:16-alpine environment: POSTGRES_DB: nexaspace POSTGRES_PASSWORD: ${DB_PASSWORD} volumes: - postgres_data:/var/lib/postgresql/data restart: unless-stopped
redis: image: redis:7-alpine restart: unless-stopped
volumes: postgres_data:Cloud Providers
Section titled “Cloud Providers”AWS (ECS)
Section titled “AWS (ECS)”Deploy to AWS Elastic Container Service:
# Build and push to ECRaws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin <account>.dkr.ecr.us-east-1.amazonaws.comdocker build -t nexaspace .docker tag nexaspace:latest <account>.dkr.ecr.us-east-1.amazonaws.com/nexaspace:latestdocker push <account>.dkr.ecr.us-east-1.amazonaws.com/nexaspace:latest
# Deploy to ECSaws ecs update-service --cluster production --service nexaspace --force-new-deploymentGoogle Cloud Platform
Section titled “Google Cloud Platform”Deploy to Cloud Run:
# Build and deploygcloud builds submit --tag gcr.io/PROJECT_ID/nexaspacegcloud run deploy nexaspace \ --image gcr.io/PROJECT_ID/nexaspace \ --platform managed \ --region us-central1 \ --allow-unauthenticatedAzure Container Instances
Section titled “Azure Container Instances”# Create resource groupaz group create --name nexaspace-rg --location eastus
# Create containeraz container create \ --resource-group nexaspace-rg \ --name nexaspace \ --image <registry>/nexaspace:latest \ --dns-name-label nexaspace \ --ports 3000Kubernetes
Section titled “Kubernetes”Deployment Manifest
Section titled “Deployment Manifest”apiVersion: apps/v1kind: Deploymentmetadata: name: nexaspacespec: replicas: 3 selector: matchLabels: app: nexaspace template: metadata: labels: app: nexaspace spec: containers: - name: nexaspace image: nexaspace:latest ports: - containerPort: 3000 env: - name: NODE_ENV value: "production" resources: requests: memory: "256Mi" cpu: "250m" limits: memory: "512Mi" cpu: "500m" livenessProbe: httpGet: path: /health port: 3000 initialDelaySeconds: 30 periodSeconds: 10 readinessProbe: httpGet: path: /ready port: 3000 initialDelaySeconds: 5 periodSeconds: 5---apiVersion: v1kind: Servicemetadata: name: nexaspace-servicespec: selector: app: nexaspace ports: - protocol: TCP port: 80 targetPort: 3000 type: LoadBalancerEnvironment Variables
Section titled “Environment Variables”Create a .env.production file:
NODE_ENV=productionPORT=3000DATABASE_URL=postgresql://user:pass@host:5432/dbREDIS_URL=redis://host:6379JWT_SECRET=your-super-secret-keyAPI_KEY=your-api-keyLOG_LEVEL=infoPerformance Optimization
Section titled “Performance Optimization”Enable Production Mode
Section titled “Enable Production Mode”import { NexaSpace } from 'nexaspace';
const app = new NexaSpace({ production: true, cache: { enabled: true, ttl: 3600 }, compression: true, clustering: true // Use all CPU cores});Load Balancing
Section titled “Load Balancing”Use a reverse proxy like Nginx:
upstream nexaspace { server app1:3000; server app2:3000; server app3:3000;}
server { listen 80; server_name api.nexaspace.com;
location / { proxy_pass http://nexaspace; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection 'upgrade'; proxy_set_header Host $host; proxy_cache_bypass $http_upgrade; }}Monitoring
Section titled “Monitoring”Set up monitoring and alerts:
import { Monitoring } from 'nexaspace';
app.use(Monitoring({ metrics: true, tracing: true, logging: { level: 'info', format: 'json' }, alerts: { errorRate: { threshold: 5, window: '5m' }, responseTime: { threshold: 1000, window: '1m' } }}));