A Node.js and Express-based RESTful API to manage school data, including adding schools and retrieving a list of schools sorted by proximity to a user-specified location. Uses MySQL for data storage.
- Add new schools with name, address, and coordinates
- Retrieve and sort schools by distance from user location
- RESTful endpoints with input validation
- Compatible with deployment platforms like Render and Railway
- Basic HTML interface for form-based interaction
🌐 API URL: [https://school-manager-api-production.up.railway.app] API URL FOR LIST SCHOOL:[https://school-manager-api-production.up.railway.app/listSchools?latitude=20&longitude=21] -> Latitute And Longitude values can be changed from the param.
- Node.js
- Express.js
- MySQL
- dotenv
- body-parser
- HTML/CSS (for basic UI)
CREATE TABLE schools (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(255),
address VARCHAR(255),
latitude FLOAT,
longitude FLOAT
);Adds a new school to the database.
Request Body (JSON):
{
"name": "Ryan International",
"address": "Jaipur",
"latitude": 26.9124,
"longitude": 75.7873
}Response:
{
"message": "School added successfully"
}Returns all schools sorted by proximity to the given location.
Query Parameters:
latitude– user's latitudelongitude– user's longitude
Example:
GET /listSchools?latitude=26.9&longitude=75.8
Response:
[
{
"id": 1,
"name": "Ryan International",
"address": "Jaipur",
"latitude": 26.9124,
"longitude": 75.7873,
"distance": 1.38
}
]Use the link below to test all endpoints:
-
Clone this repo:
git clone https://github.com/Raashika0201/school-manager-api.git cd school-management-api -
Install dependencies:
npm install
-
Create
.envfile in root with your MySQL credentials:DB_HOST=localhost DB_USER=root DB_PASSWORD=yourpassword DB_NAME=school_db
-
Start the server:
node app.js
-
Visit: [http://localhost:3000]
- Push this repo to GitHub
- Go to Railway
- Create a project → Deploy from GitHub
- Add a MySQL plugin (Railway-hosted DB)
- Set environment variables in your service
- Railway gives you a public API URL to share!
Your Name
GitHub: @raashika0201