Monorepos — a single Git repository containing multiple applications and shared packages — are how teams at Vercel, Shopify, and Microsoft manage large codebases. Turborepo adds build caching and task orchestration to make monorepo CI/CD practical: only changed packages rebuild, and cached outputs are reused across runs. Deploying a Turborepo monorepo to a Hong Kong VPS gives Asia-Pacific teams fast builds with local cache and direct CN2 GIA delivery for all apps from one infrastructure setup.
Monorepo Structure
<code"> my-monorepo/ ├── apps/ │ ├── web/ ← Next.js or SvelteKit frontend │ ├── api/ ← Node.js / Bun API server │ └── admin/ ← React admin dashboard ├── packages/ │ ├── ui/ ← Shared component library │ ├── db/ ← Database client + migrations │ └── config/ ← Shared TypeScript/ESLint config ├── turbo.json ← Turborepo pipeline config └── package.json ← pnpm workspace root
Step 1: Set Up the Monorepo
<code"># Root package.json
{
"name": "my-monorepo",
"private": true,
"packageManager": "pnpm@9.1.0",
"workspaces": ["apps/*", "packages/*"],
"scripts": {
"build": "turbo build",
"dev": "turbo dev --parallel",
"lint": "turbo lint",
"test": "turbo test"
},
"devDependencies": {
"turbo": "^2.0.0"
}
}
# turbo.json — define the task dependency graph
{
"$schema": "https://turbo.build/schema.json",
"pipeline": {
"build": {
"dependsOn": ["^build"], // Build dependencies before dependents
"outputs": [".next/**", "build/**", "dist/**"],
"cache": true
},
"test": {
"dependsOn": ["^build"],
"outputs": ["coverage/**"],
"cache": true
},
"lint": {
"outputs": [],
"cache": true
},
"dev": {
"cache": false,
"persistent": true
}
}
}
Step 2: Shared Packages
<code"># packages/db/package.json
{
"name": "@repo/db",
"main": "./src/index.ts",
"exports": {
".": "./src/index.ts",
"./schema": "./src/schema.ts"
}
}
# packages/db/src/index.ts — shared DB client used by all apps
import postgres from 'postgres'
export const createDb = (url: string) => postgres(url, {
max: 10,
idle_timeout: 30,
})
export type Db = ReturnType
# packages/ui/package.json
{
"name": "@repo/ui",
"exports": {
"./button": "./src/components/Button.tsx",
"./input": "./src/components/Input.tsx"
}
}
# apps/web/package.json — consume shared packages
{
"name": "web",
"dependencies": {
"@repo/ui": "workspace:*",
"@repo/db": "workspace:*"
}
}
Step 3: Build Only Changed Apps
<code"># Turborepo's key feature: only rebuild what changed pnpm turbo build --filter=[HEAD^1] # Only changed packages since last commit # Filter by app name pnpm turbo build --filter=api... # Build 'api' and all its dependencies # Dry run (see what would build) pnpm turbo build --dry-run # With remote caching (share cache across team and CI): pnpm turbo build --token=$TURBO_TOKEN --team=$TURBO_TEAM # First build: 3 min # Subsequent builds (cache hit): 15 seconds
Step 4: Deploy Script for HK VPS
<code"># deploy.sh — deploy only the apps that changed
#!/bin/bash
set -e
VPS_HOST="deploy@YOUR_VPS_IP"
APPS_TO_DEPLOY=$(pnpm turbo build --filter=[HEAD^1] --dry-run=json \
| jq -r '.tasks[] | select(.taskId | startswith("apps/")) | .taskId | split("#")[0] | ltrimstr("apps/")')
for APP in $APPS_TO_DEPLOY; do
echo "Deploying $APP..."
case $APP in
web)
rsync -az apps/web/.next/standalone/ $VPS_HOST:/var/www/web/
ssh $VPS_HOST "pm2 reload web --update-env"
;;
api)
rsync -az apps/api/dist/ $VPS_HOST:/var/www/api/
ssh $VPS_HOST "pm2 reload api --update-env"
;;
admin)
rsync -az apps/admin/dist/ $VPS_HOST:/var/www/admin/
ssh $VPS_HOST "nginx -s reload"
;;
esac
echo "$APP deployed ✓"
done
Step 5: PM2 Ecosystem for Multiple Apps
<code"># /var/www/ecosystem.config.cjs — manage all apps from one PM2 config
module.exports = {
apps: [
{
name: 'web',
script: '/var/www/web/server.js',
instances: 2,
exec_mode: 'cluster',
env_production: { NODE_ENV: 'production', PORT: 3001 },
},
{
name: 'api',
script: '/var/www/api/index.js',
instances: 2,
exec_mode: 'cluster',
env_production: { NODE_ENV: 'production', PORT: 3002 },
},
]
}
# pm2 start /var/www/ecosystem.config.cjs --env production
Step 6: Nginx Routing to Multiple Apps
<code">cat > /etc/nginx/sites-available/monorepo << 'EOF'
upstream web_app { server 127.0.0.1:3001; keepalive 32; }
upstream api_app { server 127.0.0.1:3002; keepalive 32; }
server {
listen 443 ssl http2;
server_name yourdomain.com;
ssl_certificate /etc/letsencrypt/live/yourdomain.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/yourdomain.com/privkey.pem;
# API routes
location /api/ {
proxy_pass http://api_app;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
}
# Frontend app
location / {
proxy_pass http://web_app;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
server {
listen 443 ssl http2;
server_name admin.yourdomain.com;
ssl_certificate /etc/letsencrypt/live/admin.yourdomain.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/admin.yourdomain.com/privkey.pem;
# Static admin SPA
root /var/www/admin;
location / {
try_files $uri $uri/ /index.html;
}
}
EOF
nginx -t && systemctl reload nginx
CI/CD with GitHub Actions
<code"># .github/workflows/deploy.yml
name: Build and Deploy
on:
push:
branches: [main]
jobs:
build-deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 2 # Needed for turbo --filter=[HEAD^1]
- uses: pnpm/action-setup@v4
with: { version: 9 }
- uses: actions/setup-node@v4
with:
node-version: 20
cache: pnpm
- run: pnpm install --frozen-lockfile
- name: Build changed apps
run: pnpm turbo build --filter=[HEAD^1]
env:
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
TURBO_TEAM: ${{ vars.TURBO_TEAM }}
- name: Deploy to HK VPS
run: bash scripts/deploy.sh
env:
SSH_KEY: ${{ secrets.DEPLOY_SSH_KEY }}
Conclusion
Turborepo monorepos deployed to a Hong Kong VPS give teams a clean architecture for multi-app Asia-Pacific products — shared UI components, a shared database client, and shared TypeScript config, with each app deployed independently to PM2 processes behind Nginx. Turborepo’s build caching means only changed apps rebuild on each commit, keeping CI/CD fast even as the monorepo grows. All apps benefit from CN2 GIA routing to mainland China from the same VPS, sharing infrastructure cost across the entire product portfolio.
Deploy your monorepo: Browse Server.HK Hong Kong VPS plans — a 4 GB VPS runs 3–5 Node.js apps from a monorepo alongside PostgreSQL and Redis comfortably.