This Node.js application serves as a RESTful API for Sri Lanka Railways, handling the ingestion, storage, and retrieval of real-time GPS location data for trains. The API supports CRUD operations on train data and maintains a 90-day data retention policy, allowing clients to access both current and historical location information.
- Ingest and store real-time GPS location data for trains.
- Retrieve current and historical location data.
- Maintain a 90-day data retention policy with automatic cleanup.
- Perform CRUD operations on train data with history logging.
- Node.js (v14 or higher)
- MongoDB
- npm (Node Package Manager)
-
Clone the repository:
git clone https://github.com/your-username/sri-lanka-railways-location-api.git
cd sri-lanka-railways-location-api
-
Install dependencies:
npm install
-
Set up environment variables:
MONGO_URI=mongodb://localhost:27017/railways
PORT=5000
-
Start the application:
npm start
-
POST /location: Ingest GPS location data for a train.
-
GET /location/:trainId: Retrieve the current location of a specific train.
-
GET /location/history/:trainId: Retrieve historical location data for a specific train.
-
GET /train-history: Retrieve CRUD operation history for trains.
-
GET /location-history: Retrieve creation history logs for locations.
The application automatically deletes location data older than 90 days, managed by a cron job running daily at midnight.
License This project is licensed under the MIT License. See the LICENSE file for details.