Skip to main content

Production Deployment

Deploy WorkForce for real-world use.

Build the Application

# Install dependencies
npm ci

# Generate Prisma client
npx prisma generate

# Build the production bundle
npm run build

This creates an optimized build in the .next folder.

Run in Production

# Apply database migrations
npx prisma migrate deploy

# Start the production server
npm start

The server runs on port 3000 by default. Use the PORT environment variable to change it.

Use a process manager to keep the application running and auto-restart on crashes.

PM2

# Install PM2
npm install -g pm2

# Start the application
pm2 start npm --name "workforce" -- start

# Save the process list (survives reboots)
pm2 save
pm2 startup

PM2 commands:

pm2 status          # Check status
pm2 logs workforce # View logs
pm2 restart workforce # Restart
pm2 stop workforce # Stop

Windows Service

On Windows Server, you can run the app as a Windows service using tools like node-windows or NSSM:

# Using NSSM (Non-Sucking Service Manager)
nssm install WorkForce "C:\Program Files\nodejs\node.exe" "C:\WorkForce\node_modules\.bin\next" start
nssm set WorkForce AppDirectory "C:\WorkForce"
nssm set WorkForce AppEnvironmentExtra "NODE_ENV=production"
nssm start WorkForce

Health Check

The application exposes a health endpoint. Set up monitoring to check it periodically:

curl http://localhost:3000/api/health

Deployment Checklist

  • NODE_ENV=production is set
  • NEXTAUTH_SECRET is a strong, random value
  • NEXTAUTH_URL matches your production domain
  • DATABASE_URL points to the production database with SSL
  • Database migrations are applied (prisma migrate deploy)
  • HTTPS is configured (via reverse proxy)
  • Process manager is installed and configured
  • Logs are being collected
  • Backups are scheduled
  • Firewall rules are configured (only 443/80 exposed)