This gets the air quality information of a nearest city using the GPS coordinates with iqair API
This section will guide you through the setup process required to get up and running with the application.
-
Node/NPM (optional yarn)
-
Mysql
-
TypeScript (
npm install -g typescript
||yarn global add typescript
)
-
Clone the project from the repository
-
Run
npm install
or yarn install from the root directory of the project -
Run
cp .env.example .env
or create a.env
file and copy the content of.env.example
to it.
-
Create a new database in mysql
-
Fill the
.env
file created with the mysql database credentials -
Run
npm run migrate
to create the tables, You can runnpm run migrate:undo
to undo the last migration ornpm run migrate:undo:all
to undo all migrations
To run the application, use the command: npm run start:dev
To run the application tests, use the command: npm run test
It is important to set up environment variables for the system to function properly
- Register on “iqair” and create your API KEY HERE
- NOTE: the activation of the key can take a few minutes (about 5 minutes).
- On your
.env
replace<YOUR API KEY>
with your generated API Key.AIR_VISUAL_API_KEY=<YOUR API KEY>
Start your node js server and call these endpoints
- GET AIR QUALITY ENDPOINT
/v1/location/nearest-city?longitude=2.352222&latitude=48.856613
[GET]
Expected Success Response (200)
{
"status": true,
"message": "Air quality retrieved successfully",
"data": {
"Result": {
"Pollution": {
"ts": "2022-09-09T06:00:00.000Z",
"aqius": 51,
"mainus": "p2",
"aqicn": 17,
"maincn": "p2"
}
}
}
}
Network Error (503)
{
"status": false,
"error": "bad_request",
"message": "Location request failed.",
"data": {
"gateway_response": "getaddrinfo ENOTFOUND api.airvisual.com"
}
}
- MOST POLLUTED TIME (PARIS - DEFAULT) ENDPOINT
/v1/location/most-polluted-time
[GET]
Expected Success Response (200)
{
"status": true,
"message": "Most polluted time retrieved successfully",
"data": {
"time": "2022-09-08T14:49:01.000Z"
}
}
- MOST POLLUTED TIME (ANY COODINATE) ENDPOINT
/v1/location/most-polluted-time?longitude=2.352222&latitude=48.856613
[GET]
Expected Success Response (200)
{
"status": true,
"message": "Most polluted time retrieved successfully",
"data": {
"time": "2022-09-08T14:49:01.000Z"
}
}
To run the cron job, use the command: npm run cron:dev
This will execute the cron task that calls the IQAIR API to get “air quality “ for the Paris zone ( latitude:
48.856613
,longitude: 2.352222
) every 1 minute then save them in the database.
Sometimes, it's necessary to send logs to the stdout or store them, to do this, make use of the exported logger
You can log errors based on their levels:
-
error
-
warn
-
info
-
debug
Example: logger.error('This is an error!')
Ensure you avoid using console.log
statements anywhere in the code.
Ensure you have eslint and prettier set up on your development environment. Ensure you follow proper linting rules as well.
Please see CHANGELOG for more information what has changed recently.
Please see CONTRIBUTING for details.
If you discover any security related issues, please email abrahamudele@gmail instead of using the issue tracker.
- Abraham Udele
Find me on
Twitter.
Linkedin.
The MIT License (MIT). Please see License File for more information.