This document provides instructions for deploying the OpenAI Assistant application to production.
- Node.js v18+
- PostgreSQL database
- OpenAI API key
- (Optional) OAuth credentials for GitHub and Google authentication
Set up the following environment variables:
DATABASE_URL: Full PostgreSQL connection stringPGHOST: PostgreSQL hostPGPORT: PostgreSQL portPGUSER: PostgreSQL usernamePGPASSWORD: PostgreSQL passwordPGDATABASE: PostgreSQL database name
SESSION_SECRET: Random string for session encryption (use a secure random generator)GITHUB_ID: GitHub OAuth client IDGITHUB_SECRET: GitHub OAuth client secretGITHUB_CALLBACK: GitHub OAuth callback URLGOOGLE_ID: Google OAuth client IDGOOGLE_SECRET: Google OAuth client secretGOOGLE_CALLBACK: Google OAuth callback URL
OPENAI_API_KEY: OpenAI API keyASSISTANT_ID: (Optional) Default OpenAI Assistant ID
SMTP_RELAY_SERVER: SMTP server for sending emailsSMTP_RELAY_PORT: SMTP portSMTP_RELAY_USER: SMTP usernameSMTP_RELAY_PASSWORD: SMTP passwordSMTP_FROM: Email sender address
NODE_ENV: Set to "production" for production deployments
- Clone the repository
- Install dependencies:
npm install - Initialize the database:
npm run db:push - Build the application for production:
npm run build - Start the application in production mode:
npm run start
The application provides a health check endpoint at /api/health that returns:
- System status
- Runtime environment
- Memory usage
- Uptime information
- Application version
This endpoint can be used with monitoring tools to ensure the application is running correctly.
The application has several production-ready features:
-
Security:
- Helmet middleware for security headers
- Rate limiting (100 requests per 15 minutes per IP)
- More aggressive rate limiting for auth endpoints (10 requests per 15 minutes)
- HTTP-only, secure cookies for sessions
- Production error handling to prevent leaking sensitive information
-
Performance:
- Compression middleware for better network performance
- Response caching for applicable API endpoints
- Optimized build process with minification
-
Reliability:
- Graceful shutdown handling for proper cleanup
- Uncaught exception handling
- Error boundary for client-side error recovery
- File upload size limits (50MB)
-
Monitoring:
- Production-appropriate logging
- Health check endpoint
- Memory usage tracking
Follow the standard deployment steps above. This is suitable for:
- VPS providers like DigitalOcean, AWS EC2, etc.
- Bare metal servers
- Self-hosted environments
Build a Docker container:
docker build -t openai-assistant-app .
docker run -p 5000:5000 --env-file .env openai-assistant-app
This approach works well with:
- Kubernetes
- Docker Swarm
- AWS ECS
- Google Cloud Run
Deploy directly to a PaaS provider:
- Heroku
- Render
- Railway
- Fly.io
Most PaaS providers will automatically detect Node.js and run the appropriate build and start commands.
- Check the log files in the
logsdirectory for application logs - Monitor the PostgreSQL database for performance issues
- Regularly back up the database
- Set up uptime monitoring using the
/api/healthendpoint - Configure alerts for error rates and performance metrics
- The application uses in-memory session store by default, which is not suitable for multiple instances. For scale-out deployments:
- Ensure database connection pooling is properly configured
- Consider using Redis for session storage in multi-instance deployments
- Use a load balancer with sticky sessions if needed
To update the application:
- Pull the latest changes
- Install dependencies:
npm install - Apply database updates:
npm run db:push - Build the application:
npm run build - Restart the application:
npm run start