-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
50 lines (41 loc) · 1.17 KB
/
Copy pathindex.js
File metadata and controls
50 lines (41 loc) · 1.17 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
43
44
45
46
47
48
49
50
const express=require('express');
const hbs=require('hbs');
const path=require('path');
const request=require('request');
const weatherdata=require(path.join(__dirname+'/utils/weatherdata'));
const app=express();
app.set('view engine','hbs');
app.set('views',path.join(__dirname+'/templates/views'));
hbs.registerPartials(path.join(__dirname+'/templates/partials'));
app.use(express.static(path.join(__dirname+'/public')));
app.get('',function(req,res){
res.render('index',{
title: 'Weather app'
});
});
app.get('/weather',function(req,res){
const address=req.query.address;
if(!address){
return res.send({
error: "Please enter any address"
})
}
weatherdata(address,(error,{temperature,description,cityName}={})=>{
if(error){
return res.send({error});
}
// console.log(temperature,description,cityName);
res.send({
temperature,description,cityName
});
})
});
app.get('*',function(req,res){
res.render('404',{
title: "page not found"
})
});
const PORT=3000 || process.env.PORT;
app.listen(PORT,()=>{
// console.log(`app is live at ${PORT}`);
});