Skip to content

Instantly share code, notes, and snippets.

@harryWonder
Last active January 18, 2022 16:48
Embed
What would you like to do?
This class makes use of the axios module to query the openWeather api to get information about the weather of a particular city.
const Axios = require('axios');
class Weather {
constructor() { }
async getWeather(cityName = 'Lagos') {
const ApiKey = 'YOUR_OPEN_WEATHER_API_KEY';
const Url = `http://api.openweathermap.org/data/2.5/weather?q=${cityName}&appid=${ApiKey}`;
await Axios.get(Url)
.then(function (resp) {
let response = resp.data;
console.log('************** Current Weather ******************');
console.log(`Description: ${response.weather[0].main}`);
console.log('**************************************************');
console.log(`Minimum Temperature: ${response.main.temp_min}`);
console.log('**************************************************');
console.log(`Maximum Temperature: ${response.main.temp_max}`);
console.log('**************************************************');
console.log(`Feels Like: ${response.main.feels_like}`);
console.log('************** Current Weather ******************');
})
.catch(function (error) {
console.log(error);
});
return;
}
}
module.exports = new Weather();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment