Chat App is packaged as a single Node.js process that serves both the REST API, WebSocket connections, and the compiled React frontend from one port. There is no separate frontend server in production — Express statically serves the Vite build output fromDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/khushboodaryani/Chat-App/llms.txt
Use this file to discover all available pages before exploring further.
frontend/dist and a catch-all route hands every non-API request to index.html so React Router can handle client-side navigation.
Prerequisites
Before you begin, make sure the following are available on your server or cloud platform:- Node.js 18 or later — the backend uses ES module syntax (
import/export) - npm — bundled with Node.js; used to install dependencies and build the frontend
- MongoDB — either a free MongoDB Atlas cluster or a self-hosted MongoDB instance reachable from your server
- Git — to clone the repository
Deployment Steps
Install backend dependencies
From the repository root, install the Node.js dependencies that power the Express and Socket.io server:
Install frontend dependencies
Move into the
frontend/ directory, install its packages, then return to the root:Build the React application
Vite compiles and bundles the React source into static files. The output is written to
frontend/dist, which Express will serve in production:Create the .env file
Create a See the Environment Variables reference for a full description of each variable.
.env file at the repository root (the same directory that contains /backend and /frontend). dotenv.config() is called inside backend/server.js, which resolves paths relative to the root:Start the server
Launch the Node.js process directly or via the npm script:Alternatively, if you have the root-level npm scripts available:You should see
Server Running on port 4000 in the console once the process connects to MongoDB successfully.Verify the deployment
Open a browser or run a quick health check to confirm the app is reachable:The app is now live at http://your-server-ip:4000. All API routes are served under
/api/*, and every other request returns the compiled React app.Keeping the Process Running with PM2
Node.js processes exit if they crash or if the terminal session closes. Use a process manager like PM2 to automatically restart the app and keep it alive across reboots:Putting the App Behind a Reverse Proxy
A minimal nginxserver block for this setup:
Upgrade and Connection headers are required to proxy Socket.io’s WebSocket connections correctly.
Security Reminders
- Store
JWT_SECRETas a long, randomly generated string (32+ characters). You can generate one withopenssl rand -hex 32. - Never commit your
.envfile to version control — add it to.gitignore. - Rotate
JWT_SECRETif you suspect it has been exposed; all existing sessions will be invalidated.