-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
46 lines (34 loc) · 1.17 KB
/
index.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
const express = require('express');
const path = require('path');
const hbs = require('hbs');
const app = express(); // All the methods & property of express are assign to app
const port = process.env.PORT || 3000;
const static_path = path.join(__dirname, '/static')
const template_path = path.join(__dirname, './templates/views'); // Line number 14 pe jo h
const particals_path = path.join(__dirname, './templates/partials');
// View Engine Handelbars Stuff
app.set('view engine', 'hbs')
app.set('views', template_path) // Iska mtlb ki line no. 13 ke jo hmne views set kra tha ab ko templates ke andr h
hbs.registerPartials(particals_path);
// Static Related Stuff
app.use(express.static(static_path));
// App Related Stuff
app.get('/', (req, res) => {
res.render('index');
})
app.get('/about', (req, res) => {
res.render('about');
})
app.get('/weather', (req, res) => {
res.render('weather');
})
// Estrick Operator (404 Error)
app.get('*', (req, res) => {
res.render('error', {
errorMsg: 'Oppos Page Not Found!' // It take an object also
});
})
// Listing the server
app.listen(port, () => {
console.log(`Your server is running at ${port} port`);
})