Skip to content

Deployment

MikroChat consists of two parts that need to be deployed:

  1. Frontend — static files (HTML, CSS, JavaScript) served by any web host
  2. Backend — Node.js application that handles the API and real-time events

The easiest way to deploy. The mikrochat CLI handles downloading, configuring, and running the API.

Terminal window
# Install the CLI
curl -sSL https://releases.mikrochat.com/install.sh | bash
# Download MikroChat
mikrochat install
# Set up your deployment directory
mkdir /opt/mikrochat && cd /opt/mikrochat
mikrochat init
# Edit mikrochat.config.json with production settings
# Start the API
mikrochat start

The mikrochat init command creates mikrochat.config.json and copies the web app to ./app/. Point your web server at the app/ directory for the frontend.

To upgrade later:

Terminal window
mikrochat upgrade

Build both parts with a single command:

Terminal window
npm run build

This creates:

  • dist/ — optimized frontend files
  • lib/ — bundled backend (ESM format)

Or build them separately:

Terminal window
npm run build:web # Frontend only
npm run build:api # Backend only

Alternatively, download a pre-built release from releases.mikrochat.com which contains both api/mikrochat.mjs and the app/ directory ready to deploy.

The frontend is a static site that can be deployed anywhere:

  • Netlify, Vercel, Cloudflare Pages
  • AWS S3 + CloudFront
  • Any web server (nginx, Apache, Caddy)
Terminal window
npm run build:web

Edit config.js in the dist/ output with your production settings. No rebuild is needed — changes take effect on page reload:

window.MIKROCHAT_CONFIG = {
API_BASE_URL: 'https://api.chat.example.com',
AUTH_MODE: 'magic-link',
ENABLE_OAUTH: false,
HAS_EMAIL: true,
MAX_CONTENT_LENGTH: 1000,
DEBUG_MODE: false
};

Upload the contents of dist/ (or app/ from a release archive) to your hosting provider:

Terminal window
# Example: deploy to a server with rsync
rsync -avz dist/ user@server:/var/www/chat/

The backend runs as a Node.js application. Deploy mikrochat.mjs to any Node.js hosting:

  • VPS (DigitalOcean, Hetzner, Linode)
  • Docker
  • Railway, Render, Fly.io
  • AWS EC2, GCP Compute Engine

Create mikrochat.config.json in the working directory, or use environment variables:

{
"auth": {
"jwtSecret": "your-production-secret-key",
"authMode": "magic-link",
"appUrl": "https://chat.example.com",
"isInviteRequired": true
},
"chat": {
"initialUser": {
"userName": "admin",
"email": "admin@example.com"
}
},
"email": {
"user": "noreply@example.com",
"host": "smtp.example.com",
"password": "smtp-password"
},
"server": {
"port": 3000,
"host": "0.0.0.0",
"allowedDomains": ["https://chat.example.com"]
}
}

Using the CLI:

Terminal window
mikrochat start

Or directly with Node.js:

Terminal window
node mikrochat.mjs

Or with environment variables:

Terminal window
PORT=3000 AUTH_JWT_SECRET=your-secret node mikrochat.mjs

Create a systemd service for automatic restarts:

/etc/systemd/system/mikrochat.service
[Unit]
Description=MikroChat Server
After=network.target
[Service]
Type=simple
User=mikrochat
WorkingDirectory=/opt/mikrochat
ExecStart=/usr/bin/node mikrochat.mjs
Restart=always
RestartSec=10
Environment="NODE_ENV=production"
[Install]
WantedBy=multi-user.target

Enable and start:

Terminal window
sudo systemctl enable mikrochat
sudo systemctl start mikrochat
sudo systemctl status mikrochat

Put MikroChat behind a reverse proxy for HTTPS and better security.

Caddy provides automatic HTTPS:

/etc/caddy/Caddyfile
# Frontend
chat.example.com {
root * /var/www/chat
file_server
try_files {path} /index.html
}
# Backend API
api.chat.example.com {
reverse_proxy localhost:3000
}

MikroChat stores data in the mikrochat_db directory (configurable via storage.databaseDirectory). Ensure this directory:

  • Persists across restarts (use Docker volumes or persistent storage)
  • Is backed up regularly
  • Has appropriate permissions

Configure allowed domains to prevent unauthorized access:

{
"server": {
"allowedDomains": [
"https://chat.example.com"
]
}
}

Use ["*"] only for development.

Enable rate limiting to prevent abuse:

{
"server": {
"rateLimit": {
"enabled": true,
"requestsPerMinute": 100
}
}
}

The backend provides a health endpoint for monitoring:

Terminal window
curl http://localhost:3000/health
# Returns: OK

Before going live:

  • Set a strong jwtSecret (use openssl rand -base64 32)
  • Set a STORAGE_KEY to enable encryption at rest
  • Configure SMTP for magic link emails
  • Set auth.authMode to "magic-link" or "password" (not "dev")
  • Configure allowedDomains (not ["*"])
  • Enable rate limiting
  • Set up HTTPS via reverse proxy or built-in SSL
  • Configure data backup for mikrochat_db
  • Back up your encryption key securely
  • Set up monitoring and health checks
  • Test the complete sign-in flow