Backend Deployment
Guide for deploying the ThePlugg backend API to production.
Prerequisites
- Production PostgreSQL database
- Environment variables configured
- Node.js 18+ on server
- Process manager (PM2 recommended)
Build
- Install dependencies
npm install
- Generate Prisma Client
npm run prisma:generate
- Run database migrations
npm run prisma:migrate
Important: Make sure NODE_ENV=production is set and database connection is correct.
- Build TypeScript
npm run build
This creates the dist/ directory with compiled JavaScript.
Running in Production
Using PM2
- Install PM2 globally
npm install -g pm2
- Start the application
pm2 start dist/index.js --name theplugg-api
- Save PM2 configuration
pm2 save
pm2 startup
Using Docker
Create a Dockerfile:
FROM node:18-alpine
WORKDIR /app
COPY package*.json ./
COPY prisma ./prisma/
RUN npm ci --only=production
RUN npx prisma generate
COPY . .
RUN npm run build
EXPOSE 3000
CMD ["node", "dist/index.js"]
Build and run:
docker build -t theplugg-api .
docker run -p 3000:3000 --env-file .env theplugg-api
Environment Variables
Ensure all production environment variables are set:
- Database connection
- JWT secret
- AWS credentials
- BulkSMS credentials
- OneSignal credentials
- CORS allowed origins
Health Check
The API provides a health check endpoint:
GET /health
Use this for monitoring and load balancer health checks.
Monitoring
- Set up logging (consider Winston or similar)
- Monitor database connection
- Set up error tracking (Sentry, etc.)
- Monitor API response times
Security Checklist
- Use HTTPS
- Set secure CORS origins
- Use strong JWT secret
- Enable rate limiting
- Regular security updates
- Database backups enabled
- API key protection enabled