The Climate Change API is a Node.js Express backend that allows you to manage climate data and calculate climate change based on various parameters such as temperature, humidity, and chances of rain. This README provides instructions on setting up and running the API.
These instructions will help you set up and run the Climate Change API on your local machine for development and testing purposes.
Before getting started, make sure you have the following software installed on your system:
-
Clone this repository to your local machine:
git clone https://github.com/your-username/climate-change-api.git
-
Install all the dependencies:
npm i
-
Create a
.env
file in the project root and set your environment variables. You can use.env.example
as a template. -
Start the server:
npm start
The server will be running on http://localhost:5000 or at the port you have specified in the
.env
file.
- URL:
/api/climate-data/add-data
- Method: POST
- Payload:
{ "climate": "hot" | "humid" | "rainy" | "cold", "area_code": 111, "temperature": 25, "humidity": 88, "chances_of_rain": 40 }
- Response:
{ "success": true | false, "error": "If success is false, this will be set else it will be null and it's value would be the reason why the saving of data failed", "data": { "id": "any_random_unique_id" } }
- URL:
/api/climate-data
- Method: GET
- Response: An array of climate data records
- URL:
/api/climate-data/area/:area_code
- Method: GET
- Response: An array of climate data records for the specified area code
- URL:
/api/climate-data/area/:area_code/climate/:climate
- Method: GET
- Response: An array of climate data records for the specified area code and climate
-
URL:
/api/climate-data/climate-change
-
Method: POST
-
Payload:
{ "from_climate": "hot" | "humid" | "rainy" | "cold", "to_climate": "hot" | "humid" | "rainy" | "cold", "area_code": xxx }
-
Response:
{ "climateDelta": "hot -> cold", "temperatureDelta": -67, "humidityDelta": 79, "rainChancesDelta": 20, "climateChangeIndex": "(delta Temp * delta Humidity)/delta rainChances" }
Please replace xxx
with the actual area code you want to use when hitting the endpoints.
To seed data for testing, you can run the seed.js
script:
node seed.js
This will insert sample data into your database.