1
0
CompleteNodeJS/weather-app/utils/forecast.js
Jason Williams 5ffdfbbb98 Video 40
2019-09-29 12:36:49 -06:00

18 lines
681 B
JavaScript

const request = require('request')
const forecast = (latitude, longitude, callback) => {
const url = 'https://api.darksky.net/forecast/0466bccb953c0b9daeb091a529da2c0d/' + latitude + ',' + longitude + '?units=si'
request({ url, json: true }, (error, {body}) => {
if (error) {
callback('Unable to connect to weather service!', undefined)
} else if (body.error) {
callback('Unable to find location', undefined)
} else {
callback(undefined, body.daily.data[0].summary + ' It is currently ' + body.currently.temperature + ' degrees out. There is a ' + body.currently.precipProbability + '% chance of rain.')
}
})
}
module.exports = forecast