Skip to main content

Documentation 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.

Chat App’s backend exposes a REST API mounted at /api. The API is organised into three resource groups — auth, messages, and users — covering everything from account creation to real-time message delivery. Public auth endpoints require no credentials; every other endpoint is protected by a JWT stored in an HttpOnly cookie that is set automatically when a user signs up or logs in.

Base URL

EnvironmentBase URL
Developmenthttp://localhost:4000
ProductionSame origin as the frontend (relative paths work)
In development the Express server runs on port 4000. When the app is deployed the API and frontend share the same domain, so you can use relative paths like /api/auth/login from the client.

Authentication

Chat App uses JWT cookies for session management. On a successful signup or login the server calls generateTokenAndSetCookie, which writes a signed JWT into an HttpOnly cookie named jwt with a 15-day expiry. The browser attaches this cookie to every subsequent same-origin request automatically. Protected routes run the protectRoute middleware, which reads req.cookies.jwt, verifies it with JWT_SECRET, and attaches the matching User document to req.user. No Authorization header is needed — the cookie is the only credential the API looks for.
Cookie namejwt
StorageHttpOnly (not accessible via document.cookie)
Expiry15 days from issue
ScopeSame-site, same-origin

Endpoint Inventory

MethodPathAuth RequiredDescription
POST/api/auth/signupNoRegister a new user account
POST/api/auth/loginNoLog in and receive a JWT cookie
POST/api/auth/logoutNoLog out and clear the JWT cookie
GET/api/messages/:idYesFetch conversation history with a user
POST/api/messages/send/:idYesSend a message to a user
GET/api/usersYesList all users except the logged-in user

Response Format

All endpoints return JSON. Successful responses return the requested resource or a confirmation object. Error responses always use the shape below, making it straightforward to render a single error handler on the client.
{ "error": "A human-readable error message" }
Success responses return either the resource directly or a message object:
{ "message": "Logged out successfully" }
HTTP status codes follow standard semantics: 200 for successful reads, 201 for successful resource creation, 400 for validation errors, 401/404 for auth/not-found failures, and 500 for unexpected server errors.
In development the jwt cookie is not marked Secure, so it transmits over plain HTTP on localhost. When you deploy, set NODE_ENV=production and serve the app over HTTPS — the server will then add the Secure flag automatically.

Explore the API

Authentication API

Signup, login, and logout endpoints with full request and response schemas.

Messages API

Send messages and retrieve conversation history between two users.

Users API

List all registered users to populate the sidebar contacts list.

WebSocket Events

Real-time newMessage and online-status events delivered via Socket.io.

Build docs developers (and LLMs) love