The backend of Codehive is built using Node.js and Express, designed to provide a real-time collaborative coding environment. It enables seamless communication (video calling and chat), dynamic room management and code synchronization using Socket.IO. Additionally, the backend ensures robust functionality with periodic health checks and task scheduling.
-
Real-Time Collaboration
- Synchronize code changes across all users in a room in real time.
- Broadcast cursor positions to enhance teamwork and visibility.
-
Room Management
- Create unique rooms using UUID for collaborative sessions.
- Manage participants, including handling joins, leaves and disconnections.
-
Integrated Communication
- Supports video and audio toggling, ensuring a smooth virtual coding experience.
-
Health Monitoring
- Periodic server health checks via a dummy route using Node-Cron.
-
Scalable Architecture
- Seamless integration with frontend through environment variables for flexible deployments.
-
Core Frameworks and Libraries:
-
Utilities:
- CORS: Ensures secure communication between the frontend and backend.
- dotenv: Manages environment variables for flexible configuration.
-
Socket.IO Events
chat_message
: Facilitates real-time messaging among users.create_room
: Dynamically creates rooms with a unique ID.join_room
: Allows users to join existing rooms and synchronizes room data.code_change
: Updates code across participants in real time.toggle_video
andtoggle_audio
: Handles user media preferences.disconnect
: Cleans up rooms and user data upon disconnection.
-
API Endpoints
GET /
: Verifies server availability with a basic response.GET /keep-alive
: Keeps the server active by simulating requests.
-
Cron Jobs
- Executes a scheduled health check every 8 minutes to ensure server reliability.
Follow the steps below to set up and run the backend server for Codehive:
-
Node.js (v16+ recommended)
-
npm or yarn
-
A
.env
file with the following environment variables:FRONTEND_URL=<Frontend_URL> BACKEND_URL=<Backend_URL>
-
Clone the Repository
git clone https://github.com/codehiveofficial/codehive-server.git cd codehive-server
-
Install Dependencies
# Using npm npm install # Or using yarn yarn install
-
Set Up Environment Variables
Create a.env
file in the root directory and add the required environment variables as shown above. -
Run the Development Server
node server.js
The server will run at the specified
PORT
(default: 5000). You can check its status by visitinghttp://localhost:5000
. -
Verify the Setup
Access the/
endpoint in your browser or via Postman to confirm the server is up and running.
By completing these steps, your backend will be fully operational and ready to support the Codehive platform. 🚀