This is the backend for the real-time chat application using Express, Socket.IO, and MongoDB (Mongoose).
It supports real-time messaging, likes, and comments.
- Clone the repository:
git clone <repo-url>
cd <repo-folder>- Install dependencies:
npm install- Install nodemon globally (optional, for development):
npm install -g nodemonOr as a dev dependency:
npm install --save-dev nodemonCreate a .env file in the src/ folder based on the .env.example file:
src/.env.example
Example .env:
MONGO_URI=mongodb:
PORT=3000MONGO_URI— Your MongoDB connection stringPORT— Port for the server (default: 3000)
npx nodemon src/index.jsor if installed globally:
nodemon src/index.jsnode src/index.jssrc/
├─ models/ # Mongoose schemas (Message, Comment, etc.)
├─ server.js # Express & Socket.IO setup
├─ index.js # Entry point
├─ .env.example # Environment variable template
- Messages, likes, and comments are persisted in MongoDB.
- Socket.IO handles real-time updates.
- Ensure MongoDB is running before starting the server.