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 Timescale

πŸš€ pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applicationsβ€”without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read full post β†’

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

AWS GenAI Live!

GenAI LIVE! is a dynamic live-streamed show exploring how AWS and our partners are helping organizations unlock real value with generative AI.

Tune in to the full event

DEV is partnering to bring live events to the community. Join us or dismiss this billboard if you're not interested. ❀️