A RESTful API built with Node.js, Express.js, and MySQL for managing school data.
The API allows users to:
- Add new schools
- Retrieve schools sorted by proximity to a user's location
This project is deployed using:
- Render (Backend Hosting)
- Railway (MySQL Database)
Both services are running on their free tiers.
Because of this:
- The API may take 30–60 seconds to respond on the first request after inactivity.
- Railway databases may occasionally sleep when unused for extended periods.
- Temporary delays or cold starts are expected on the first API call.
If the API appears unresponsive initially, please wait briefly and retry the request.
https://school-api-hfj5.onrender.com
You can verify the API is active using:
GET /Expected response:
{
"success": true,
"message": "School Management API is running"
}- Node.js + Express.js
- MySQL Database
- ES Modules
- Input Validation
- Distance Calculation using Haversine Formula
- Sorted Nearby Schools
- Clean Folder Structure
- Node.js
- Express.js
- MySQL
- mysql2
- express-validator
- dotenv
- cors
- nodemon
school-management-api/
│
├── config/
│ └── db.js
│
├── controllers/
│ └── schoolController.js
│
├── routes/
│ └── schoolRoutes.js
│
├── .env
├── .gitignore
├── package.json
├── README.md
├── server.js
└── schema.sqlNote: The application is hosted on Render and Railway free tiers, so the first request may take some time due to cold starts.
POST https://school-api-hfj5.onrender.com/addSchool
{
"name": "Green Valley School",
"address": "Mumbai",
"latitude": 19.0760,
"longitude": 72.8777
}{
"success": true,
"message": "School added successfully"
}name→ requiredaddress→ requiredlatitude→ valid float between -90 and 90longitude→ valid float between -180 and 180
GET https://school-api-hfj5.onrender.com/listSchools?latitude=19.0760&longitude=72.8777
{
"success": true,
"count": 2,
"data": [
{
"id": 1,
"name": "Green Valley School",
"address": "Mumbai",
"latitude": 19.076,
"longitude": 72.8777,
"distance_km": 0
},
{
"id": 2,
"name": "Sunrise Public School",
"address": "Pune",
"latitude": 18.5204,
"longitude": 73.8567,
"distance_km": 120.52
}
]
}GET https://school-api-hfj5.onrender.com/test-db
{
"success": true,
"rows": [
{
"1": 1
}
]
}The API uses the Haversine Formula to calculate the geographical distance between the user and each school.
This ensures accurate earth-surface distance calculations.
const response = await fetch(
"https://school-api-hfj5.onrender.com/listSchools?latitude=19.0760&longitude=72.8777"
);
const data = await response.json();
console.log(data);Akash Damle