/NodeJsApi

APIs using Node.js, Express.js framework, and MySQL to manage school data

Primary LanguageJavaScript

Nodejs API

Technologies Getting Started API Endpoints

A simple Node.js API using Express and MySQL to manage schools.

💻 Technologies

  • Nodejs
  • Express.js
  • MySQL
  • Postman

🚀 Getting started

How to Run Project Locally

Prerequisites

prerequisites necessary for running your project.

  • Node.js
  • MySQL
  • NPM

Cloning

How to clone your project

git clone https://github.com/yourusername/school-management-api.git
cd school-management-api

Config .env variables

DB_HOST=your_database_host
DB_USER=your_database_user
DB_PASSWORD=your_database_password
DB_NAME=school_management
PORT=3000

Starting

How to start your project

node app.js

📍 API Endpoints

Here you can list the main routes of your API, and what are their expected request bodies. ​

route description
GET /api/listSchools?latitude=lat&longitude=lon List schools sorted by distance
POST /api/addSchooll Add a new school[request details]

GET /api/listSchools?latitude=39.78&longitude=-89.64

RESPONSE

[
    {
        "id": 1,
        "name": "Springfield Elementary",
        "address": "742 Evergreen Terrace, Springfield",
        "latitude": 39.78,
        "longitude": -89.64,
        "distance": 0.0
    },
    {
        "id": 2,
        "name": "Shelbyville High",
        "address": "123 Main St, Shelbyville",
        "latitude": 39.90,
        "longitude": -89.70,
        "distance": 12.3
    }
]

POST /api/addSchool

REQUEST

{
    "name": "Springfield Elementary",
    "address": "742 Evergreen Terrace, Springfield",
    "latitude": 39.78,
    "longitude": -89.64
}

RESPONSE

{
    "message": "School added successfully",
    "schoolId": 1
}