Deploy a Turborepo Monorepo to Your Own Server

Deploy a Turborepo or pnpm/npm workspaces monorepo with Temps: one project per app directory, shared managed Postgres, branch previews and per-app monitoring.

David Viejo
David Viejo · Updated · Published

To deploy a Turborepo (or pnpm, npm or Yarn workspaces) monorepo to your own server with Temps, create one Temps project per app and set each project's app directory to that app's folder. Every project builds from the same repository with its own environment variables, deployment history and health checks, and managed services such as PostgreSQL can be linked to several projects at once.


How do you deploy a monorepo to a self-hosted platform?

Most platforms make you choose: deploy the whole repository as one app, or split it into separate repositories. Temps uses separate projects that point at different directories of the same repository, each with its own build, environment variables and deployment lifecycle.

Git repository: my-monorepo
  Temps project: my-saas-web  →  directory: apps/web  (preset: nextjs)
  Temps project: my-saas-api  →  directory: apps/api  (preset: nixpacks-node)

Each project has its own deployment history and environment variables. Preview environments, rollbacks and HTTPS certificates are per project too.


Temps vs. other platforms for monorepo deployments

PlatformMonorepo supportPreview environmentsManaged servicesSelf-hostedMonthly cost
TempsOne project per app, each with its own app directoryYes, per branch (opt-in, per project)PostgreSQL, Redis, MongoDB and S3-compatible storage on your serverYes, free (MIT / Apache 2.0)Free to self-host (you pay for the server); Temps Cloud, a hosted control plane for your own servers, $29/mo (invite-only beta)
VercelOne project per app, each with its own root directoryYesThrough Marketplace integrations (Neon, Upstash and others)NoSee vercel.com/pricing
RailwayOne service per app, each with its own root directoryYesDatabase templates (PostgreSQL, Redis, MySQL, MongoDB)NoSee railway.com/pricing

Vercel and Railway cells checked October 2026.

What that means in practice for a monorepo on Temps:

  • Per-project isolation. Each app is a separate Temps project with its own deployment history, environment variables and health checks, so one app's failed build doesn't block the others.
  • Shared services. One PostgreSQL or Redis service can be linked to several projects; each project gets the connection variables injected.
  • Observability per app. Analytics, error tracking and uptime monitoring are per project, on the same server, without a separate observability stack to wire up.

Tutorial: deploying a Next.js + Express monorepo

Prerequisites

  • A monorepo with a web and an api app (Turborepo or any workspace manager)
  • The repository on GitHub, GitLab or another Git provider connected to Temps
  • A running self-hosted Temps instance (see the quickstart)

Typical monorepo structure

my-monorepo/
  apps/
    web/           # Next.js frontend
      package.json
      next.config.ts
    api/           # Express/Fastify backend
      package.json
  packages/
    shared/        # Shared types, utils
      package.json
    ui/            # Shared UI components
      package.json
  package.json     # Root with workspaces
  turbo.json       # Turborepo config (optional)

Step 1: Authenticate

bunx @temps-sdk/cli login https://console.example.com

Step 2: Create a project for each app

Use --directory to point each project at its app folder. The same setting is called App Directory in the project settings (Projects):

# Frontend: Next.js is detected from next.config.ts
bunx @temps-sdk/cli projects create -n "My SaaS Web" -d "Next.js frontend"
bunx @temps-sdk/cli projects git -p my-saas-web \
  --owner myorg --repo my-monorepo --branch main \
  --directory apps/web --preset nextjs -y

# API: a plain Node.js service needs the Autopack (Node.js) preset
bunx @temps-sdk/cli projects create -n "My SaaS API" -d "Express API backend"
bunx @temps-sdk/cli projects git -p my-saas-api \
  --owner myorg --repo my-monorepo --branch main \
  --directory apps/api --preset nixpacks-node -y

Temps builds each project from its directory. Shared packages under packages/ are resolved through your workspace configuration, and Turborepo, Nx and Lerna are detected from their config files (monorepo tools).

Step 3: Set environment variables

Each project has its own variables:

# Frontend variable
bunx @temps-sdk/cli environments vars set NEXT_PUBLIC_API_URL "https://api.myapp.com" \
  -p my-saas-web -e production

# API secrets: leave the value out and the CLI prompts for it,
# so it doesn't end up in your shell history
bunx @temps-sdk/cli environments vars set JWT_SECRET -p my-saas-api -e production
bunx @temps-sdk/cli environments vars set STRIPE_SECRET_KEY -p my-saas-api -e production

You can also import an existing .env file:

bunx @temps-sdk/cli environments vars import .env.production -p my-saas-web -e production

Step 4: Set up a shared database

Create a PostgreSQL service once and link it to both projects. Linking injects POSTGRES_URL and the POSTGRES_* variables (not DATABASE_URL) into each project's next deployment:

# Create a managed PostgreSQL service (note its numeric ID)
bunx @temps-sdk/cli services create -t postgres -n my-saas-db -y

# Link it to both projects
bunx @temps-sdk/cli services link --id 1 -p my-saas-web
bunx @temps-sdk/cli services link --id 1 -p my-saas-api

# Check the injected variables
bunx @temps-sdk/cli services env --id 1 -p my-saas-web
bunx @temps-sdk/cli services env --id 1 -p my-saas-api

Temps doesn't run database migrations. Run them once after a deploy that changes the schema, from the project that owns them; how to run database migrations safely shows how.

Step 5: Deploy

Push to main. Each project tracking that branch starts its own deployment on every push, whichever directory changed:

git push

Or deploy a single project from the CLI:

bunx @temps-sdk/cli deploy -p my-saas-web -b main -e production -y
bunx @temps-sdk/cli deploy -p my-saas-api -b main -e production -y

Handling shared packages

The tricky part of a monorepo deploy is shared code. If apps/web imports from packages/shared, the build needs that package too.

With Turborepo

Turborepo 2 calls the build graph tasks (version 1 called it pipeline; npx @turbo/codemod migrate upgrades an old config):

{
  "$schema": "https://turbo.build/schema.json",
  "tasks": {
    "build": {
      "dependsOn": ["^build"],
      "outputs": [".next/**", "dist/**"]
    },
    "dev": {
      "cache": false,
      "persistent": true
    }
  }
}

Temps detects turbo.json and runs the build scoped to the project's directory, so dependsOn: ["^build"] builds packages/shared first.

With pnpm workspaces

# pnpm-workspace.yaml
packages:
  - "apps/*"
  - "packages/*"

With npm or Yarn workspaces

{
  "workspaces": ["apps/*", "packages/*"]
}

Preview deployments for monorepos

Turn on preview environments for each project that should get them (set up preview deployments). When you push a branch, each of those projects deploys its own preview to an environment named after the branch, with a URL in the form <project>-<branch>.<your-domain>:

Branch feature/login pushed:
  my-saas-web → https://my-saas-web-feature-login.yourdomain.com
  my-saas-api → https://my-saas-api-feature-login.yourdomain.com

Each preview is independent, so you can test frontend changes against the API's preview.

Point the frontend preview at the API preview

Preview environments are named after the branch (feature/login becomes feature-login), so you can set a variable for one branch's preview:

bunx @temps-sdk/cli environments vars set NEXT_PUBLIC_API_URL \
  "https://my-saas-api-feature-login.yourdomain.com" \
  -p my-saas-web -e feature-login

Custom domains and automatic SSL

Point A records at your server's IP, then add the domains:

TypeNameValue
Amyapp.comYOUR_SERVER_IP
Aapi.myapp.comYOUR_SERVER_IP
# HTTP-01 challenge (default)
bunx @temps-sdk/cli domains add -d myapp.com
bunx @temps-sdk/cli domains add -d api.myapp.com

# Wildcard: needs the DNS-01 challenge
bunx @temps-sdk/cli domains add -d "*.myapp.com" --challenge dns-01

Temps issues the certificates from Let's Encrypt. For a wildcard (*.myapp.com), the CLI shows the TXT record to add.


Monitoring both projects

# Stream logs per project
bunx @temps-sdk/cli runtime-logs -p my-saas-web -f
bunx @temps-sdk/cli runtime-logs -p my-saas-api -f

# Deployment history
bunx @temps-sdk/cli deployments list -p my-saas-web
bunx @temps-sdk/cli deployments list -p my-saas-api

# Roll back one app to its previous deployment
bunx @temps-sdk/cli deployments rollback -p my-saas-api -e production

Each project has its own CPU and memory usage, request metrics, errors and deployment history.


Real-world monorepo patterns

Pattern 1: Next.js + tRPC

apps/
  web/        # Next.js with tRPC client
  api/        # tRPC server
packages/
  trpc/       # Shared router definitions

Deploy as two Temps projects linked to the same PostgreSQL service.

Pattern 2: Frontend + background worker

apps/
  web/        # Next.js frontend
  worker/     # Queue processor (BullMQ)
packages/
  jobs/       # Shared job definitions

Temps runs each project's web process and health-checks it over HTTP, so give the worker a small HTTP server (a /health route is enough) and deploy it as its own project, linked to the same Redis.

Pattern 3: Several sites, one repository

apps/
  app/        # Main application (app.myproduct.com)
  marketing/  # Marketing site (myproduct.com)
  docs/       # Documentation (docs.myproduct.com)
  api/        # Shared API
packages/
  ui/         # Shared design system
  auth/       # Shared auth logic

Four Temps projects, one repository, each with its own domain and deployment lifecycle.


Moving from several repositories to a monorepo

If you deploy separate repositories today:

# Restructure
mkdir -p apps
mv ../frontend apps/web
mv ../backend apps/api

# Update the workspace config
# package.json: "workspaces": ["apps/*", "packages/*"]

# Point the existing Temps projects at the new repository and directories
bunx @temps-sdk/cli projects git -p my-web --owner myorg --repo my-monorepo --directory apps/web -y
bunx @temps-sdk/cli projects git -p my-api --owner myorg --repo my-monorepo --directory apps/api -y

git push

From then on, a push to the tracked branch deploys both projects from the same commit, so the frontend and the API never drift apart.


Frequently Asked Questions

Does Temps support Turborepo and Nx monorepos?

Yes. Temps detects Turborepo (turbo.json), Nx (nx.json) and Lerna (lerna.json) and runs the build scoped to each project's app directory, with npm, Yarn, pnpm or Bun workspaces.

Does a push redeploy every app in the monorepo?

Every project tracking the pushed branch starts a deployment, whether or not its directory changed. To deploy only some apps on a push, turn off automatic deploys for the others (projects config --no-auto-deploy) and trigger them with deploy from CI.

Can several apps in a monorepo share one database on Temps?

Yes. Create one managed PostgreSQL (or Redis) service and link it to each project; every linked project gets POSTGRES_URL and the other connection variables injected.

How do preview deployments work for a monorepo on Temps?

Each project with previews turned on deploys a preview for a pushed branch to <project>-<branch>.<your-domain>. Point one app's preview at another's by setting a variable on the branch's preview environment.


Temps is free to self-host (MIT / Apache 2.0). Temps Cloud, a hosted control plane for your own servers, is $29/month in an invite-only beta. Using Nx, Lerna or another monorepo tool? See monorepo tools and set the app directory per project as above.

#monorepo#turborepo#deployment#tutorial#next.js#express