Creating Weather App using Weather API and Node Js : Part Two

In part one 👉👉 (Part One) we made our API get the longitudes of the location we want. In this part we are really going to get the weather data of the location using another API.

We are going to use Weather Stack.The first step to using the API is to …


This content originally appeared on DEV Community and was authored by Adolph Odhiambo

In part one 👉👉 (Part One) we made our API get the longitudes of the location we want. In this part we are really going to get the weather data of the location using another API.

We are going to use Weather Stack.The first step to using the API is to authenticate with your weatherstack account's unique API access key, which can be found in your account dashboard after registration. To authenticate with the API, simply use the base URL below and pass your API access key to the API's access_key parameter.

http://api.weatherstack.com/current
    ? access_key = YOUR_ACCESS_KEY
    & query = {coordinates}

Weather Stack is easy to integrate and there is an option of passing the place name you want to get the weather here is an example

http://api.weatherstack.com/current
    ? access_key = YOUR_ACCESS_KEY
    & query = New York

But today we are going to use the geoCoding where we will pass the coordinates returned from the geoCode function we created in part One.In part one the function returns an object so to access the latitude will be cordinates.latitude and longitude we use cordinates.latitude.

geoCode("Nairobi").then(async function(cordinates){
   response = await axios.get(`http://api.weatherstack.com/current?access_key=**your Accesskey&query=${cordinates.latitude},${cordinates.longitude}&units=m`)
   const description=response.data.current.weather_descriptions[0];
   const temperature = response.data.current.temperature;
   const timeTaken = response.data.current.observation_time;


})

This code will get us the weather data but we are going to only use the description ,temperature and time the data was recorded.

In the next part we will be structuring our files and start working with express


This content originally appeared on DEV Community and was authored by Adolph Odhiambo


Print Share Comment Cite Upload Translate Updates
APA

Adolph Odhiambo | Sciencx (2022-07-13T22:34:48+00:00) Creating Weather App using Weather API and Node Js : Part Two. Retrieved from https://www.scien.cx/2022/07/13/creating-weather-app-using-weather-api-and-node-js-part-two/

MLA
" » Creating Weather App using Weather API and Node Js : Part Two." Adolph Odhiambo | Sciencx - Wednesday July 13, 2022, https://www.scien.cx/2022/07/13/creating-weather-app-using-weather-api-and-node-js-part-two/
HARVARD
Adolph Odhiambo | Sciencx Wednesday July 13, 2022 » Creating Weather App using Weather API and Node Js : Part Two., viewed ,<https://www.scien.cx/2022/07/13/creating-weather-app-using-weather-api-and-node-js-part-two/>
VANCOUVER
Adolph Odhiambo | Sciencx - » Creating Weather App using Weather API and Node Js : Part Two. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/07/13/creating-weather-app-using-weather-api-and-node-js-part-two/
CHICAGO
" » Creating Weather App using Weather API and Node Js : Part Two." Adolph Odhiambo | Sciencx - Accessed . https://www.scien.cx/2022/07/13/creating-weather-app-using-weather-api-and-node-js-part-two/
IEEE
" » Creating Weather App using Weather API and Node Js : Part Two." Adolph Odhiambo | Sciencx [Online]. Available: https://www.scien.cx/2022/07/13/creating-weather-app-using-weather-api-and-node-js-part-two/. [Accessed: ]
rf:citation
» Creating Weather App using Weather API and Node Js : Part Two | Adolph Odhiambo | Sciencx | https://www.scien.cx/2022/07/13/creating-weather-app-using-weather-api-and-node-js-part-two/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.