You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A high-performance Node.js/Express backend server for a real-time, location-aware chat application. It features user authentication, geo-based nearby user discovery, persistent messaging, real-time WebSocket communication via Socket.IO, media uploads to AWS S3 with on-the-fly FFmpeg video compression/transcoding, and push notifications through the Expo push service.
Features
User Registration & Authentication — Register with location data; log in with 30-minute access tokens and 7-day refresh tokens.
Real-Time Messaging — Bidirectional, instant messaging over WebSocket (Socket.IO) with sub-millisecond delivery, delivered to both sender and receiver rooms.
REST Messaging API — HTTP endpoints to send and retrieve conversation history.
Media & Video Processing — Video upload pipeline with automatic FFmpeg H.264/AAC transcoding, 720:1280 aspect ratio scaling/cropping, and streaming upload to AWS S3.
Nearby User Discovery — Find other users within a configurable radius (km) using the Haversine formula with offset-based pagination.
Location Management — Store and update each user's latitude/longitude coordinates.
Expo Push Notifications — Sends a push notification to a recipient's device whenever a new message is received.
Password Security — Passwords hashed with bcrypt (cost factor 10).
CORS Enabled — Configurable origins via CORS_ORIGINS.
Get nearby users within radius (km) with pagination
GET
/users/connections
Get user friendships / connections
GET
/users/requests
Get incoming friend requests
POST
/send-friend-request
Send a friend request
POST
/accept-friend-request
Accept a pending friend request
PUT
/users/video
Upload and transcode user profile video to S3
PUT
/users/location
Update user GPS coordinates
PUT
/users/profile
Update age, gender, or sexuality
PUT
/update-description
Update user bio / description
PUT
/update-push-token
Register Expo push token
DELETE
/users
Delete user account and associated data
PUT /users/video
Headers:Authorization: Bearer <accessToken>, Content-Type: multipart/form-data Body:video (file up to 25MB) Process: Automatically transcodes video to 720x1280 H.264/AAC with faststart, uploads to AWS S3, and links to user profile.
Messages
Method
Endpoint
Description
POST
/messages
Send message (saves to DB and emits over Socket.IO)
GET
/messages
Retrieve conversation history between users
WebSocket Events (Socket.IO)
Connect with Socket.IO client using JWT authentication in the handshake:
Event Loop Lag: P50 = 27.67 ms, P99 = 34.57 ms under heavy load.
Memory Consumption: Base RSS = 90.15 MB, V8 Heap Used = 29.03 MB.
🛠️ Performance Optimization Recommendations
Video Storage Stream Ingestion: Transition from multer.memoryStorage() to multer.diskStorage() to prevent allocating 25 MB buffers directly in the V8 heap during video uploads.
Threadpool Scaling: Configure UV_THREADPOOL_SIZE=16 in production to prevent CPU-bound bcrypt password verifications from saturating default worker threads.
Spatial Indexing: Add a PostgreSQL B-Tree bounding box filter or PostGIS GiST index on (latitude, longitude) for /nearby-users to avoid table scans on high user counts.
Push Notification Offloading: Delegate Expo push notifications to a background worker queue (e.g. BullMQ / Redis) so external network calls do not block WebSocket event acknowledgments.