set view property
app.set('views', __dirname + '/views');
before setting view engine
Example
const port = process.env.PORT || 3000
// defining and using static files(i.e html)
app.use(express.static(path.join(__dirname, "../public")))
//engine added after editing answer
app.engine('.hbs', exphbs({ defaultLayout: 'main', extname: '.hbs' }));
// necessary for templates
app.set('views', __dirname + '/views');
// defining handle bar engine
app.set("view engine", "hbs")
// this is just for test
app.get("/", (req, res) => {
res.render("index")
})
Edited to add:
Hbs engine was not declared. Should be before set view
app.engine('.hbs', exphbs({ defaultLayout: 'main', extname: '.hbs' }));
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…