Skip to content

Instantly share code, notes, and snippets.

@harryWonder
Last active January 18, 2022 16:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save harryWonder/ae3a66c6349dab3c139d52c13d8ce539 to your computer and use it in GitHub Desktop.
Save harryWonder/ae3a66c6349dab3c139d52c13d8ce539 to your computer and use it in GitHub Desktop.
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