forked from nikhils4/Weather-web-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
weather.js
31 lines (26 loc) · 987 Bytes
/
weather.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
const request = require("request");
var getWeather = (lat, lan, callback) => {
request ({
url : 'https://api.darksky.net/forecast/61043ce7510ce565a6616401169c0fba/' + lat + ',' + lan,
json : true
}, (error, response, body) => {
if(error){
callback('Unable to connect to server try again later !');
}
else if (response.statusCode===400){
callback('Unable to fetch weather try again later !');
}
else if(response.statusCode===200){
callback(undefined, {
temperature : body.currently.temperature,
icon : body.currently.icon,
prediction : body.hourly.summary,
summary : body.currently.summary,
wind : body.currently.windSpeed,
humidity : body.currently.humidity,
pressure : body.currently.pressure
})
}
});
};
module.exports.getWeather = getWeather;