-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
55 lines (41 loc) · 1.11 KB
/
app.js
File metadata and controls
55 lines (41 loc) · 1.11 KB
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
32
33
34
35
36
37
38
39
40
41
42
// Open Weather map API
var weather = require('./weather.js'); // WHen using a local file you must type ./
var location = require('./location.js');
var argv = require('yargs')
.option('location', {
alias: 'l',
demand: false,
describe: 'Location to fetch weather for',
type: 'string'
})
.help('help')
.argv;
if (typeof argv.l === 'string' && argv.l.length > 0) {
console.log('Location was provided');
// weather(argv.l, function (currentWeather) {
// console.log(currentWeather);
// });
weather(argv.l).then(function(currentWeather){
console.log(currentWeather);
}).catch(function(error){
console.log(error);
})
} else {
// console.log('Location was not provided');
// location(function (location) {
// if (location){
// weather(location.city, function(currentWeather) {
// console.log('However, ' + currentWeather);
// });
// } else {
// console.log('Unable to guess location');
// }
// });
location().then(function(loc){
return weather(loc.city);
}).then(function(currentWeather){
console.log(currentWeather);
}).catch(function(error){
console.log(error);
})
}