Deployment Procedures
Deployment Procedures
This section outlines the steps required to deploy the HCG AI application to production environments such as Replit, Render, or Railway.
1. Environment Configuration
Before deploying, ensure all required environment variables are configured in your hosting provider's "Secrets" or "Environment Variables" panel.
| Variable | Description | Requirement |
| :--- | :--- | :--- |
| DATABASE_URL | PostgreSQL connection string (e.g., Neon, AWS RDS). | Required |
| OPENAI_API_KEY | API key from OpenAI for chatbot functionality. | Required |
| SESSION_SECRET | A long, random string used to sign session cookies. | Required |
| SMTP_PASS | Password/App key for the SMTP server (hello@in.hcgai.com). | Required for Emails |
| PORT | The port the server listens on (defaults to 5000). | Optional |
| NODE_ENV | Set to production to enable secure cookies. | Recommended |
2. Database Provisioning
The application uses PostgreSQL with Drizzle ORM. You must provision a database instance before the application can start.
- Obtain a Connection String: Use a provider like Neon.tech (recommended for serverless) or a standard PostgreSQL instance.
- Initialize Schema: Once the
DATABASE_URLis set, push the schema to your remote database:npm run db:push - Session Table: The application uses
connect-pg-simplefor persistent sessions. Ensure thesessionstable is created. IfcreateTableIfMissingis set to false in your configuration, you may need to run the official schema SQL manually viapsql.
3. Deploying to Replit
Replit is a preferred environment for this application due to its integrated handling of Node.js services.
- Import Repository: Connect your GitHub account and import the
hcgairepository. - Configure Secrets: Add the variables listed in the Environment Configuration section to the Tools > Secrets tab.
- Configure Run Command: Ensure the
.replitfile or the "Run" button is configured to execute:Note: If you are using the simplified version, usenpm startnode simple-app-server.js. - Database Migration: Open the Replit Shell and run
npm run db:pushto sync the schema with your connected database.
4. Deploying to Generic Node.js Hosting (Render/Railway/Heroku)
For standard cloud hosting providers:
- Build Command: Most providers will automatically run
npm install. No additional build step is required for the vanilla JS frontend. - Start Command: Set the start command to:
node simple-app-server.js - Networking: Ensure the platform is configured to listen on
0.0.0.0rather than127.0.0.1to allow external traffic.
5. SMTP and API Integrations
- Email Services: The application is pre-configured for Hostinger SMTP. If using a different provider (e.g., SendGrid, Mailgun), you must update the
hostandportin thecreateEmailTransporterfunction withinsimple-app-server.js. - OpenAI: Ensure your OpenAI account has sufficient credits; otherwise, the "AI Chat" tab will return 500 errors.
6. Post-Deployment Verification
After deployment, verify the following:
- Health Check: Navigate to
https://your-app-url.com/health(if usingauth-server.js) to confirm the service is statushealthy. - Database Connection: Attempt to register a new user. If the registration fails with a "500" error, check your
DATABASE_URLand ensure theuserstable exists. - SSL/HTTPS: Verify that the site is served over HTTPS. The application's session cookies are configured with
secure: truein production environments, which requires an SSL certificate to maintain user sessions.
7. Troubleshooting
- Session Disconnects: If users are logged out immediately after login, ensure
NODE_ENVis set toproductionand you are accessing the site viahttps. - CORS Issues: If the frontend cannot reach the API, verify that the
corsmiddleware insimple-app-server.jsallows your production domain.