这里是代码,因为我正在使用动态模板的手把,但是当我运行服务器时它无法正常工作,它显示的是静态HTML文件,而不是.hbs文件。
const path = require('path')
const express = require('express')
const app = express()
//define path for express config
const directory = path.join(__dirname, '../public')
const viewPath = path.join(__dirname, '../templates')
//setup handlebars engine and views location
app.set('view engine', 'hbs');
app.set('views', viewPath)
//setup static directory to serve
app.use(express.static(directory))
app.get('', (req,res)=>{
res.render('index',{
title: 'Weather App',
name: 'Bial Ahmed'
})
})
app.get('/about',(req,res)=>{
res.render('about',{
title: 'About Me'
})
})
app.listen(3000, ()=> {
console.log('server is running on 3000')
})