Titan Planet Logo
How to Use Titan

9. Production Deployment

Learn how to bundle, distribute, and secure your TitanPL application for high-performance production environments.

TitanPL is designed for high-performance production environments. Its deployment process ensures that all security policies, extensions, and pre-computed routes are packed into a portable, production-ready bundle.


๐Ÿ—๏ธ Production Build (titan build --release)

The titan build --release command is the standard way to package your application for production.

What it Does:

  1. V8 Bundle: Minifies and bundles all your actions into a single optimized runtime.
  2. Route Pre-computation: Generates a static map of all actions for faster startup.
  3. Security Assets: Automatically copies tanfig.json and package.json to the distribution.
  4. Extension Bundling: Scans node_modules for any titan.json files and copies the entire extension tree into a specialized .ext/ directory.
  5. Binary Extraction: Pulls the correct platform-specific engine binary into the bundle root.

๐Ÿ› ๏ธ Custom Assets & Build Configuration

You can control which folders and files are carried over to your production build/ folder by adding a build block to your tanfig.json.

{
  "name": "my-app",
  "build": {
    "files": ["public", "static", "db", "certs", "custom-assets"],
    "env": "production"
  }
}

Supported Fields:

  • files: An array of folder/file names in your project root to copy into the build/ directory. By default, TitanPL copies public, static, db, and tanfig.json.
  • env: Set to production or deploy to disable the creation of local symlinks in favor of a clean, standalone file structure.

๐Ÿ›ก๏ธ Production Safety Management

Deploying TitanPL to Docker is straightforward because the build/ directory is self-contained.

Sample Dockerfile:

# ================================================================
# STAGE 1 โ€” Builder
# ================================================================
FROM node:20-bookworm-slim AS builder

WORKDIR /app

# Install build dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
    build-essential pkg-config \
    && rm -rf /var/lib/apt/lists/*

ENV NODE_ENV=production
ENV TITAN_DEV=0

# Copy dependency files
COPY package.json package-lock.json* ./

# Install Titan CLI and dependencies
RUN npm install -g @titanpl/cli
RUN npm install --include=optional

# Copy source code
COPY . .

# Build the Titan app
RUN titan build --release

# ================================================================
# STAGE 2 โ€” Runtime
# ================================================================
FROM ubuntu:24.04

WORKDIR /app

# Minimal runtime deps
RUN apt-get update && apt-get install -y --no-install-recommends \
    ca-certificates curl \
    && rm -rf /var/lib/apt/lists/*

# Create dedicated user
RUN groupadd -r titan && useradd -r -g titan titan

# Copy ALL contents from builder stage build/ directory to current WORKDIR
COPY --from=builder /app/build/ ./

# Map .ext into 'dist' and 'app' to satisfy all potential loader paths.
RUN ln -s /app/.ext /app/dist/.ext || true && \
    ln -s /app/.ext /app/app/.ext || true

# Fix ownership
RUN chown -R titan:titan /app

# Environment variables
ENV HOST=0.0.0.0
ENV PORT=5100
ENV TITAN_DEV=0
# Help the dynamic linker find the .so files
ENV LD_LIBRARY_PATH=/app/.ext/@titanpl/core/native/target/release

USER titan
EXPOSE 5100

# Run the native server executable
CMD ["./titan-server", "run", "dist"]

๐Ÿ›ก๏ธ Critical Security Checklist

Before deploying to production, ensure the following are correct:

1. tanfig.json Checklist

  • allowNative only contains extensions you trust.
  • allowWasm is only true if your extensions rely on it.
  • Your project name in tanfig.json matches the root configuration.

2. Engine Visibility

  • Titan-native host processes run out-of-process for security. If you are using a firewall or restrictive OS policy, ensure IPC pipes from the engine to its spawned sub-processes are allowed.

๐Ÿš€ Execution in Production

Once your build/ folder is on the server, you can start it with zero external dependencies:

cd build
./titan-server run dist

Zero-Downtime: Use a process manager like pm2 to monitor the titan-server binary and ensure it stays online during system reboots or crashes.


Summary

  • Use titan build --release for a self-contained production bundle.
  • Configure tanfig.json for custom assets and security permissions.
  • Deploy the build/ folder to any Linux or Windows server.
  • No Node.js runtime required on the server (just the binary).

On this page