-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
62 lines (53 loc) · 1.7 KB
/
app.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
const yargs = require('yargs');
const express= require('express');
const fs=require('fs');
const ejs=require('ejs');
const geocode = require('./geocode/geocode');
const weather = require('./weather/weather');
app.set('view engine',"ejs");
app.use('/',express.static('assets'));
var app=express();
const port = process.env.PORT || 3000;
app.get("/",(req,res)=>{
// var file=fs.createReadStream(__dirname+"/index.html","utf8");
// file.pipe(res);
res.render('index');
});
app.get("/data",(req,res)=>{
var address=req.query.address;
// console.log(address);
geocode.geocodeAddress(address, (errorMessage, results) => {
if(errorMessage) {
var text = 'Unable to find the address';
res.render('data',{text});
}
else{
// console.log(results.address);
weather.getWeather(results.latitude, results.longitude, (errorMessage, weatherResults) => {
if(errorMessage){
console.log(errorMessage);
}
else{
var text='Location : '+ results.address+`\nIt's currently ${weatherResults.temperature} ℉ . \nIt feels like ${weatherResults.apparentTemperature} ℉.`;
res.render('data',{text});
}
});
}
});
});
app.listen(port, () => {
console.log(`Started up at port ${port}`);
});
// const argv = yargs
// .options({
// a: {
// demand: true,
// alias: 'address',
// describe: 'Address to fetech weather for',
// string: true
// }
// })
// .help()
// .alias('help', 'h')
// .argv;
//console.log(argv);