Skip to content

Deploying a LibreChat App

Introduction

LibreChat is an open-source chatbot and prompt orchestration platform built on Node.js. Deploying LibreChat with a Dockerfile on Klutch.sh provides reproducible builds, managed secrets, and persistent storage for conversation history and assets—all configured from klutch.sh/app. This guide covers installation, repository prep, a production-ready Dockerfile, deployment steps, Nixpacks overrides, sample API usage, and production tips.


Prerequisites

  • A Klutch.sh account (create one)
  • A GitHub repository containing your LibreChat code/config (GitHub is the only supported git source)
  • Docker familiarity and Node.js 18+ knowledge
  • MongoDB credentials (required) and optional Redis for caching/rate limiting
  • API keys for LLM providers (OpenAI, Azure, etc.) as needed

For onboarding, see the Quick Start.


Architecture and ports

  • LibreChat serves HTTP; set the internal container port to 3080.
  • MongoDB and Redis should run as separate Klutch.sh TCP apps, exposed on port 8000 and connected internally on 27017 and 6379.
  • Persistent storage is recommended for uploads, logs, and optional local cache.

Repository layout

librechat/
├── Dockerfile # Must be at repo root for auto-detection
├── package.json
├── pnpm-lock.yaml # or yarn.lock / package-lock.json
├── .env.example # Template only; no secrets
├── data/ # Uploads/logs (mount as volume)
└── README.md

Keep secrets out of Git; store them in Klutch.sh environment variables.


Installation (local) and starter commands

Install dependencies and run locally before pushing to GitHub:

Terminal window
pnpm install
pnpm build
pnpm start -- --port 3080

Optional helper start.sh for portability and Nixpacks fallback:

#!/usr/bin/env bash
set -euo pipefail
pnpm prisma migrate deploy || true
exec pnpm start -- --port 3080

Make it executable with chmod +x start.sh.


Dockerfile for LibreChat (production-ready)

Place this Dockerfile at the repo root; Klutch.sh auto-detects it (no Docker selection in the UI):

FROM node:18-alpine AS build
WORKDIR /app
COPY package.json pnpm-lock.yaml* yarn.lock* package-lock.json* ./
RUN corepack enable
RUN pnpm install --frozen-lockfile
COPY . .
RUN pnpm build
FROM node:18-alpine
WORKDIR /app
ENV NODE_ENV=production PORT=3080
COPY --from=build /app /app
RUN corepack enable && pnpm install --prod --frozen-lockfile
EXPOSE 3080
CMD ["pnpm", "start", "--", "--port", "3080"]

Notes:

  • Add build tools (apk add --no-cache python3 make g++) in the build stage if native modules are required.
  • Keep data/ writable and mount it as a volume for uploads and logs.

Environment variables (Klutch.sh)

Set these in the Klutch.sh app settings (Secrets tab) before deploying:

  • NODE_ENV=production
  • PORT=3080
  • MONGODB_URI=mongodb://<user>:<password>@<host>:<port>/<db>
  • REDIS_URL=redis://<user>:<password>@<host>:<port> (if using Redis)
  • JWT_SECRET=<secure-jwt-secret>
  • NEXTAUTH_SECRET=<secure-nextauth-secret> (if applicable)
  • Provider keys (e.g., OPENAI_API_KEY, AZURE_OPENAI_ENDPOINT, etc.)

If you deploy without the Dockerfile and need Nixpacks overrides:

  • NIXPACKS_BUILD_CMD=pnpm install --frozen-lockfile && pnpm build
  • NIXPACKS_START_CMD=pnpm start -- --port 3080
  • NIXPACKS_NODE_VERSION=18

These keep LibreChat compatible with Nixpacks defaults when a Dockerfile is absent.


Attach persistent volumes

In Klutch.sh storage settings, add mount paths and sizes (no names required):

  • /app/data — for uploads, logs, and any local cache.

Ensure this path is writable inside the container.


Deploy LibreChat on Klutch.sh (Dockerfile workflow)

  1. Push your repository (with the Dockerfile at the root) to GitHub.
  2. Open klutch.sh/app, create a project, and add an app.
  1. Connect the GitHub repository; Klutch.sh automatically detects the Dockerfile.
  2. Choose HTTP traffic for LibreChat.
  3. Set the internal port to 3080.
  4. Add the environment variables above (MongoDB/Redis URLs, secrets, provider keys, and any NIXPACKS_* overrides if you temporarily deploy without the Dockerfile).
  5. Attach persistent volumes for /app/data, choosing sizes that match your storage needs.
  6. Deploy. Your LibreChat app will be reachable at https://example-app.klutch.sh; attach a custom domain if desired.

Sample API usage

Send a message to LibreChat’s API (replace placeholders):

Terminal window
curl -X POST "https://example-app.klutch.sh/api/conversation" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer <token>" \
-d '{"prompt": "Hello from Klutch.sh!"}'

Health checks and production tips

  • Add a reverse proxy health check to / or a lightweight status route.
  • Enforce HTTPS at the edge; forward HTTP to port 3080 internally.
  • Keep lockfiles committed and Node version pinned for reproducible builds.
  • Monitor MongoDB/Redis performance; set connection pools appropriate to your deployment size.
  • Rotate JWT/NextAuth secrets and provider keys regularly; store them only in Klutch.sh secrets.
  • Monitor disk usage on /app/data and resize volumes before they fill.

LibreChat on Klutch.sh combines reproducible Docker builds with managed secrets, persistent storage, and flexible HTTP/TCP routing. With the Dockerfile at the repo root and port 3080 configured, you can deliver secure, scalable chatbot experiences without extra YAML or workflow overhead.