A RESTful API server built with Node.js and Express.js to support real-time messaging operations.
- User authentication with JWT
- Secure password storage using bcrypt
- CRUD operations for users and messages
- Real-time chat support via WebSocket (Socket.IO)
- MongoDB database integration using Mongoose ORM
- Input validation with Joi
- Error handling and structured logging
| Layer | Technology |
|---|---|
| Runtime | Node.js (ES Modules) |
| Framework | Express.js |
| Database | MongoDB (Mongoose) |
| Authentication | JWT + bcrypt |
| Socket Library | Socket.IO |
| Validation | Joi |
git clone https://github.com/naderianaliakbar/Messenger-Back-End.git
cd Messenger-Back-End
npm installCopy .env.example to .env and configure:
PORT=5000
MONGODB_URI=mongodb://localhost:27017/messenger-db
JWT_SECRET=your_jwt_secretnpm run dev # Run in development mode with nodemon
npm start # Run in production modeAPI will be available at http://localhost:5000.
-
Auth
POST /api/auth/register– Register new userPOST /api/auth/login– Login and receive JWT
-
Users (protected)
GET /api/users– List all usersGET /api/users/:id– Get user by ID
-
Messages (protected)
GET /api/messages/:chatId– List messages in a chatPOST /api/messages– Send a new message
Real-time WebSocket events (via Socket.IO):
connection,disconnect– socket lifecyclemessage,typing,read– chat events
Include Jest or Mocha/Chai setup if you plan to add unit/integration tests. Example:
npm testsrc/
├── controllers/
├── models/
├── routes/
├── services/
├── middlewares/
├── utils/
└── index.js
- Always include
Authorization: Bearer <JWT>header when using protected routes - Use WS or Socket.IO clients for real-time message handling
Fork the repo, create feature branches, and submit PRs. Please follow best practices for code quality and testing.
This project is licensed under the MIT License.