This class makes use of the axios module to query the openWeather api to get information about the weather of a particular city.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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