1
0
CompleteNodeJS/weather-app/utils/forecast.js

18 lines
694 B
JavaScript
Raw Normal View History

2019-08-25 21:16:02 +00:00
const request = require('request')
const forecast = (latitude, longitude, callback) => {
const url = 'http://api.weatherstack.com/current?access_key=360ee65db0f798aa09021f493b5b02c9&query=' + latitude + ',' + longitude + '&units=m'
2019-08-25 21:16:02 +00:00
2019-09-29 18:36:49 +00:00
request({ url, json: true }, (error, {body}) => {
2019-08-25 21:16:02 +00:00
if (error) {
callback('Unable to connect to weather service!', undefined)
2019-09-29 18:36:49 +00:00
} else if (body.error) {
2019-08-25 21:16:02 +00:00
callback('Unable to find location', undefined)
} else {
callback(undefined, body.current.weather_descriptions[0] + '. It is currently ' + body.current.temperature + ' degress out. It feels like ' + body.current.feelslike + ' degress.')
2019-08-25 21:16:02 +00:00
}
})
}
module.exports = forecast