DEV Community

Cover image for Creating Weather App using Weather API and Node Js : Part Two
Adolph Odhiambo
Adolph Odhiambo

Posted on

1 1

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 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}

Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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;


})
Enter fullscreen mode Exit fullscreen mode

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

Image of Stellar post

Check out Episode 1: How a Hackathon Project Became a Web3 Startup πŸš€

Ever wondered what it takes to build a web3 startup from scratch? In the Stellar Dev Diaries series, we follow the journey of a team of developers building on the Stellar Network as they go from hackathon win to getting funded and launching on mainnet.

Read more

Top comments (0)

πŸ‘‹ Kindness is contagious

Dive into this insightful write-up, celebrated within the collaborative DEV Community. Developers at any stage are invited to contribute and elevate our shared skills.

A simple "thank you" can boost someone’s spiritsβ€”leave your kudos in the comments!

On DEV, exchanging ideas fuels progress and deepens our connections. If this post helped you, a brief note of thanks goes a long way.

Okay