Skip to main content

Production Setup

This document outlines the steps required to set up OsmoX for production. Following these steps will ensure that your application is configured properly for a production environment.

Prerequisites

Node.js v20.x+

Install via NVM

PostgreSQL v16.x+

Production database server

Redis v6.x+

Queue backend

PM2 v5.x+

Process manager for Node.js

Docker v26.1.2

Container runtime (optional)

Git v2.x+

Version control
Ensure Redis and PostgreSQL servers are running.

Environment Configuration

Create the .env file with production values:
cp .env.example .env
Update these critical production values:
VariableDescription
NODE_ENVSet to production
SERVER_PORTAPI server port
DB_HOSTPostgreSQL host
DB_PORTPostgreSQL port
DB_USERNAMEDatabase username
DB_PASSWORDDatabase password
REDIS_HOSTRedis host
REDIS_PORTRedis port
API_KEY_SECRETSecret for API key encryption
JWT_SECRETSecret for JWT tokens

Build the Application

Before starting the server, build OsmoX:
npm run build
This compiles TypeScript code into JavaScript and generates the necessary build files.

Deployment Options

PM2 Deployment

1. Create PM2 ConfigurationCreate an ecosystem.config.js file:
module.exports = {
  apps: [
    {
      name: 'OsmoX',
      script: 'dist/main.js',
      instances: 1,
      autorestart: true,
      watch: false,
      max_memory_restart: '1G',
      env: {
        NODE_ENV: 'production',
      },
    },
  ],
};
2. Start with PM2
pm2 start ecosystem.config.js
3. Enable Auto-Start on Boot
pm2 startup
Follow any instructions provided by the command.4. Save PM2 Configuration
pm2 save

Updating Environment Variables

If you need to update environment variables in a Docker deployment:
1

Update .env file

Modify the values in your .env file
2

Stop containers

docker compose stop
docker compose down -v
3

Rebuild containers

docker compose build
4

Start containers

docker compose up -d

Next Steps

Usage Guide

Learn how to make API calls and send notifications