-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
44 lines (34 loc) · 1004 Bytes
/
Copy pathapp.js
File metadata and controls
44 lines (34 loc) · 1004 Bytes
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
const path = require('path');
const hbs = require('hbs');
const express = require('express');
const app = express();
const PORT=8000
const staticPath = path.join(__dirname)
// console.log(__dirname)
app.use(express.static(staticPath)); //isse hum koi bhi static file run krwa skte hai
//We need to write this peice of code to render a file on particular path
const pathName = path.join(__dirname,'/templates/views')
// console.log(pathName)
const partialsPath = path.join(__dirname,'/templates/partials')
app.set('view engine', 'hbs')
app.set('views', pathName)
hbs.registerPartials(partialsPath)
app.set('env development');
app.get('/', (req, res) => {
res.render('home')
})
app.get('/about', (req, res) => {
res.render('about')
})
app.get('/home', (req, res) => {
res.render('home')
})
app.get('/weather', (req, res) => {
res.render('weather')
})
app.get('*', (req, res) => {
res.render('error')
})
app.listen(PORT , ()=>{
console.log(`Listening on port ${PORT}`)
})