Skip to content

Latest commit

 

History

History
112 lines (78 loc) · 3.08 KB

File metadata and controls

112 lines (78 loc) · 3.08 KB

🚨 Post-Accident Alert System Backend

This repository contains the backend server for a Post-Accident Alert System, designed to facilitate real-time communication and emergency response coordination using WebSockets and REST APIs.


🌟 Features

Real-time Communication: Uses WebSockets for instant data exchange between clients.
REST API Support: Handles HTTP requests to process alert signals.
CORS Configuration: Enables cross-origin communication.
Hospital Nearest Location Finder: Identifies and broadcasts the nearest hospital based on accident location.
WebSocket Broadcast: Sends emergency data to all connected clients.


🛠 Technologies Used

🚀 Node.js – Server-side JavaScript runtime
🚀 Express.js – Lightweight web framework
🚀 WebSocket (ws) – Handles real-time bi-directional communication
🚀 Body-Parser – Parses incoming request bodies
🚀 CORS – Enables cross-origin resource sharing


📥 Installation

1️⃣ Clone the Repository

 git clone https://github.com/your-username/raamprathap-post-accident-alert-system-backend.git
 cd raamprathap-post-accident-alert-system-backend

2️⃣ Install Dependencies

 npm install

3️⃣ Start the Server

 npm start

The server will run on PORT 3000 by default. You can configure this using the PORT environment variable.


🔌 API Endpoints

🟢 WebSocket Connection

  • WebSocket server is available at /signal

📡 REST API

  • POST /signal - Accepts JSON data to process accident alerts.

Example Usage:

curl -X POST -H "Content-Type: application/json" -d '{"type": "hospital_request", "lat": "12.3456", "lng": "78.9101"}' http://localhost:3000/signal

🔗 WebSocket Example

const ws = new WebSocket('ws://localhost:3000');

ws.onopen = function () {
    console.log('✅ WebSocket connection established.');
    ws.send(JSON.stringify({ type: 'hospital_request', lat: 12.3456, lng: 78.9101 }));
};

ws.onmessage = function (event) {
    console.log('📩 Message received:', event.data);
};

⚙️ Configuration

  • CORS Setup: Modify server.js to allow specific origins.
  • Port Configuration: Change PORT in environment variables as needed.

🤝 Contributing

🚀 Contributions are welcome! If you want to improve the project:

  1. Fork the repository 🍴
  2. Create a new branch 🔀
  3. Make your changes ✏️
  4. Submit a pull request 📬

📜 License

This project is licensed under the ISC License. See the LICENSE file for details.


Authors


💡 Built with passion by Raamp and akshayks13 🚀