Anonymous real-time chat app built with React, Express, Socket.IO, and MongoDB Atlas.
The frontend and backend are meant to run together from the Express server. In deployment, use the app on https://anonymous-chatting-website.onrender.com/ so room creation, messaging, uploads, and sockets all use the same origin.
- React + Vite
- Express
- Socket.IO
- MongoDB Atlas with Mongoose
- Multer for file uploads
- Create chat rooms
- Join existing rooms
- Send real-time text messages
- Upload and share files
- Persist rooms and messages in MongoDB
- Health endpoint for app and database status
.
├─ dist/ Production frontend build served by Express
├─ uploads/ Uploaded files
├─ server.cjs Express + Socket.IO + MongoDB backend
├─ connect.cjs MongoDB connectivity check script
├─ index.html Vite entry HTML
├─ main.js Frontend source entry used by the build pipeline
└─ .env Local environment variables
- Node.js installed
- A MongoDB Atlas cluster
- A MongoDB Atlas database user
- Your current machine IP added to Atlas
Network Access
Create a .env file in the project root:
MONGODB_URI=mongodb+srv://username:password@cluster0.example.mongodb.net/anonymouschat?retryWrites=true&w=majority
DB_NAME=anonymouschat
PORT=5000Notes:
MONGODB_URIshould be your Atlas connection string.DB_NAMEis the database name used by the app.PORT=5000is the recommended local app port.- The server also supports
ATLAS_URIorATLAS URI, butMONGODB_URIis preferred.
npm installStart the full app:
npm startThen open:
https://anonymous-chatting-website.onrender.com/
Important:
- Use
5000, not the Vite preview URL, for full app testing. - The backend serves the built frontend and all API routes from the same origin.
npm startruns the Express server and serves the appnpm run devstarts the Vite dev servernpm run buildbuilds the frontend intodistnpm run previewpreviews the built frontend onlynode connect.cjschecks MongoDB connectivity
The backend exposes:
GET /api/health
Example successful response:
{
"ok": true,
"app": "anony",
"database": {
"status": "connected",
"databaseName": "anonymouschat",
"source": "MONGODB_URI",
"lastConnectedAt": "2026-05-21T09:57:42.986Z",
"retryAt": null,
"error": null
}
}GET /api/roomslist room codesPOST /api/roomscreate a room
Example request:
{
"code": "my-room"
}GET /api/rooms/:code/messagesget room messagesPOST /api/rooms/:code/messagescreate a text or file message
POST /api/uploadupload a file- Uploaded files are served from
/uploads/...
If room creation fails, check these first:
- Run
node connect.cjsto verify Atlas connectivity. - Confirm your current IP is allowed in Atlas
Network Access. - Confirm the username and password inside
MONGODB_URI. - Make sure the cluster is active and not paused.
- Open
https://anonymous-chatting-website.onrender.com/api/healthand inspect thedatabaseobject.
If Atlas is unreachable, the server now stays up and reports database status clearly instead of crashing immediately.
Recommended local workflow:
- Update
.envwith a valid Atlas URI. - Run
node connect.cjs. - Start the app with
npm start. - Open
https://anonymous-chatting-website.onrender.com/. - Create a room and test messaging.
The repo includes a render.yaml setup. For deployment:
- Set
MONGODB_URIin the hosting provider environment variables - Set
DB_NAME - Use
npm startas the start command - Point the health check to
/api/health