-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserver.js
More file actions
68 lines (55 loc) · 1.85 KB
/
server.js
File metadata and controls
68 lines (55 loc) · 1.85 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
const express = require('express');
const hbs = require('hbs'); //view engine for express app
const fs = require('fs');
let port = process.env.PORT || 3000;
let app = express(); //Creates an Express application
//registering partials and helper
hbs.registerPartials(__dirname + '/views/partials');
hbs.registerHelper('getCurrentYear',()=>new Date().getFullYear());
hbs.registerHelper('screamIt', (text)=> text.toUpperCase())
app.set('view engine','hbs'); //setting view engine for app
app.use((req,res,next)=>{
var timeStamp = new Date().toString();
fs.appendFile('server.log',`${timeStamp} : ${req.method}, ${req.url} \n`,(err)=>{
if(err) console.log('unablet to log the file.');
})
next();
});//app middleware to log server-request
// app.use((req,res,next)=>{
// res.render('maintenance.hbs');
// })// middleware in-case of site maintenance
app.use(express.static(__dirname + '/public'));
app.get('/',(req,res)=>{
res.render('home.hbs',{
pageTitle :'Weather app',
welcomeMessage:'Welcome to app',
features : [
'show min temp', 'show max temp','humidity','windSpeed', 'latitude','longitude'
]
});
});
app.get('/project',(req,res)=>{
res.render('project.hbs', {
pageTitle: 'Portfolio',
welcomeMessage:"It is my portfolio page",
projectList:'Car Rental System'
});
});
app.get('/about',(req,res)=>{
res.render('about.hbs',{
pageTitle:'About Page'
});
});
app.get('/features',(req,res)=>{
res.send({
temperature:'44C',
weather :'Mostly cloudly',
max_temperature:'45c',
min_temperature: '35c',
});
});
app.get('/bad',(req,res)=>{
res.send({ECODE:404,
errorMessage:'Page not found error 404'});
});
app.listen(port,()=> console.log(`Server is running at ${port}`)); //start server