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

18 lines
681 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 = 'https://api.darksky.net/forecast/0466bccb953c0b9daeb091a529da2c0d/' + latitude + ',' + longitude + '?units=si'
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 {
2019-09-29 18:36:49 +00:00
callback(undefined, body.daily.data[0].summary + ' It is currently ' + body.currently.temperature + ' degrees out. There is a ' + body.currently.precipProbability + '% chance of rain.')
2019-08-25 21:16:02 +00:00
}
})
}
module.exports = forecast