Before deploying, ensure you have:
- Node.js 18+ installed
- MongoDB database (Atlas recommended)
- Cloudinary account for image storage
- Domain names (optional but recommended)
Create backend/.env file with:
# MongoDB Configuration
MONGODB_URI=mongodb+srv://username:password@cluster.mongodb.net/tars_db
# Cloudinary Configuration
CLOUDINARY_CLOUD_NAME=your_cloud_name
CLOUDINARY_API_KEY=your_api_key
CLOUDINARY_API_SECRET=your_api_secret
# CORS Configuration
CORS_ORIGIN=https://your-frontend-domain.com
# Server Configuration
PORT=4000
NODE_ENV=productionCreate frontend/.env.local file with:
# Backend API URL
NEXT_PUBLIC_CONTACT_API=https://your-backend-domain.com/api/contact
NEXT_PUBLIC_API_URL=https://your-backend-domain.com/apiUsing Railway:
- Push code to GitHub
- Go to Railway
- Create new project β Deploy from GitHub
- Select
backendfolder - Add environment variables in Railway dashboard
- Set start command:
npm start - Deploy!
Using Render:
- Go to Render
- New β Web Service
- Connect GitHub repository
- Root directory:
backend - Build command:
npm install - Start command:
npm start - Add environment variables
- Deploy!
- Go to Vercel
- Import your GitHub repository
- Root directory:
frontend - Framework preset: Next.js
- Add environment variables
- Deploy!
# Update system
sudo apt update && sudo apt upgrade -y
# Install Node.js
curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
sudo apt install -y nodejs
# Install PM2 for process management
sudo npm install -g pm2
# Install Nginx
sudo apt install nginx -y# Clone repository
git clone <your-repo-url>
cd tars-monorepo/backend
# Install dependencies
npm install --production
# Create .env file with production values
nano .env
# Start with PM2
pm2 start src/index.js --name tars-backend
pm2 save
pm2 startupcd ../frontend
# Install dependencies
npm install
# Build production
npm run build
# Start with PM2
pm2 start npm --name tars-frontend -- start
pm2 save# /etc/nginx/sites-available/tars
# Backend
server {
listen 80;
server_name api.yourdomain.com;
location / {
proxy_pass http://localhost:4000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
# Frontend
server {
listen 80;
server_name yourdomain.com www.yourdomain.com;
location / {
proxy_pass http://localhost:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}# Enable site
sudo ln -s /etc/nginx/sites-available/tars /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl restart nginx
# Setup SSL with Let's Encrypt
sudo apt install certbot python3-certbot-nginx -y
sudo certbot --nginx -d yourdomain.com -d www.yourdomain.com
sudo certbot --nginx -d api.yourdomain.com# backend/Dockerfile
FROM node:18-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production
COPY . .
EXPOSE 4000
CMD ["npm", "start"]# frontend/Dockerfile
FROM node:18-alpine AS builder
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build
FROM node:18-alpine
WORKDIR /app
COPY --from=builder /app/package*.json ./
COPY --from=builder /app/.next ./.next
COPY --from=builder /app/public ./public
COPY --from=builder /app/node_modules ./node_modules
EXPOSE 3000
CMD ["npm", "start"]version: '3.8'
services:
backend:
build: ./backend
ports:
- "4000:4000"
env_file:
- ./backend/.env
restart: unless-stopped
frontend:
build: ./frontend
ports:
- "3000:3000"
env_file:
- ./frontend/.env.local
depends_on:
- backend
restart: unless-stopped# Deploy with Docker Compose
docker-compose up -d- Environment variables configured
- MongoDB database created and accessible
- Cloudinary account setup
- CORS_ORIGIN updated to production frontend URL
- API URLs updated in frontend env
- Test build locally (
npm run build) - Remove any console.logs in production code
- Setup error monitoring (Sentry, LogRocket, etc.)
- Setup analytics (Google Analytics, etc.)
- Configure custom domain
- Setup SSL certificates
- Test all API endpoints
- Test image uploads
- Test mobile responsiveness
- Setup backup strategy for MongoDB
cd backend
NODE_ENV=production npm startcd frontend
npm run build
npm startTest at http://localhost:3000
pm2 list # List all processes
pm2 logs tars-backend # View backend logs
pm2 logs tars-frontend # View frontend logs
pm2 restart all # Restart all services
pm2 stop all # Stop all services
pm2 delete all # Remove all processesgit pull origin main
cd backend && npm install && pm2 restart tars-backend
cd ../frontend && npm install && npm run build && pm2 restart tars-frontend- Check MONGODB_URI is correct
- Whitelist server IP in MongoDB Atlas
- Verify network connectivity
- Update CORS_ORIGIN in backend .env
- Ensure frontend URL is correct
- Check if backend is accessible
- Verify Cloudinary credentials
- Check file size limits
- Ensure multer is configured correctly
- Check if backend/frontend is running:
pm2 list - Check Nginx config:
sudo nginx -t - Check logs:
sudo tail -f /var/log/nginx/error.log
For issues, contact the development team or check:
- Backend logs:
pm2 logs tars-backend - Frontend logs:
pm2 logs tars-frontend - Nginx logs:
/var/log/nginx/error.log
- Never commit
.envfiles - Use strong MongoDB passwords
- Keep dependencies updated:
npm audit fix - Enable rate limiting on API
- Setup firewall rules
- Regular backups of database
- Monitor for security vulnerabilities
- Use HTTPS only in production
- Implement proper authentication for dashboard
- Sanitize user inputs
Happy Deploying! π