A RESTful API built using Node.js, Express.js, and MySQL for managing school data.
The API allows users to:
- Add schools
- Retrieve schools sorted by geographical proximity
- Add School API
- List Schools API
- MySQL database integration
- Haversine distance calculation
- Input validation using express-validator
- Environment variable support
- Modular project structure
- Node.js
- Express.js
- MySQL
- mysql2
- express-validator
- dotenv
- Render
.
├── controllers/
├── database/
├── queries/
├── routes/
├── screenshots/
├── tests/
├── utils/
├── .env.example
├── .gitignore
├── app.js
├── jest.config.js
├── LICENSE
├── package.json
├── README.md
├── School Management API.postman_collection.json
└── server.js
git clone https://github.com/code-kasha/school_management_apicd school_management_apinpm installCreate a .env file:
PORT=5000
ENVIRONMENT=development
DB_HOST=localhost
DB_USER=root
DB_PASSWORD=yourpassword
DB_NAME=school_management
DB_PORT=3306CREATE TABLE schools (
id INT PRIMARY KEY AUTO_INCREMENT,
name VARCHAR(255) NOT NULL,
address VARCHAR(255) NOT NULL,
latitude FLOAT NOT NULL,
longitude FLOAT NOT NULL
);npm run devnpm starthttp://localhost:5000
POST /api/addSchool{
"name": "ABC Public School",
"address": "Mumbai, Maharashtra",
"latitude": 19.076,
"longitude": 72.8777
}{
"success": true,
"message": "School Added"
}GET /api/listSchools?latitude=19.0760&longitude=72.8777{
"success": true,
"count": 2,
"data": [
{
"id": 1,
"name": "ABC Public School",
"address": "Mumbai",
"latitude": 19.076,
"longitude": 72.8777,
"distance_km": 0
}
]
}Deployed using Render.
Note: The deployed API may take a few seconds to respond on the first request due to Render free-tier cold starts.
Import the included Postman collection:
School_Management_API.postman_collection.json
MIT License