Skip to content

Deployment

NexaSpace applications can be deployed to any cloud platform or on-premises infrastructure.

Create a Dockerfile in your project root:

FROM node:20-alpine
WORKDIR /app
# Copy package files
COPY package*.json ./
# Install dependencies
RUN npm ci --only=production
# Copy source code
COPY . .
# Build application
RUN npm run build
# Expose port
EXPOSE 3000
# Health check
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD node healthcheck.js
# Start application
CMD ["npm", "start"]

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:

Deploy to AWS Elastic Container Service:

Terminal window
# Build and push to ECR
aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin <account>.dkr.ecr.us-east-1.amazonaws.com
docker build -t nexaspace .
docker tag nexaspace:latest <account>.dkr.ecr.us-east-1.amazonaws.com/nexaspace:latest
docker push <account>.dkr.ecr.us-east-1.amazonaws.com/nexaspace:latest
# Deploy to ECS
aws ecs update-service --cluster production --service nexaspace --force-new-deployment

Deploy to Cloud Run:

Terminal window
# Build and deploy
gcloud builds submit --tag gcr.io/PROJECT_ID/nexaspace
gcloud run deploy nexaspace \
--image gcr.io/PROJECT_ID/nexaspace \
--platform managed \
--region us-central1 \
--allow-unauthenticated
Terminal window
# Create resource group
az group create --name nexaspace-rg --location eastus
# Create container
az container create \
--resource-group nexaspace-rg \
--name nexaspace \
--image <registry>/nexaspace:latest \
--dns-name-label nexaspace \
--ports 3000
apiVersion: apps/v1
kind: Deployment
metadata:
name: nexaspace
spec:
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: v1
kind: Service
metadata:
name: nexaspace-service
spec:
selector:
app: nexaspace
ports:
- protocol: TCP
port: 80
targetPort: 3000
type: LoadBalancer

Create a .env.production file:

Terminal window
NODE_ENV=production
PORT=3000
DATABASE_URL=postgresql://user:pass@host:5432/db
REDIS_URL=redis://host:6379
JWT_SECRET=your-super-secret-key
API_KEY=your-api-key
LOG_LEVEL=info
import { NexaSpace } from 'nexaspace';
const app = new NexaSpace({
production: true,
cache: {
enabled: true,
ttl: 3600
},
compression: true,
clustering: true // Use all CPU cores
});

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;
}
}

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'
}
}
}));