xxxxxxxxxx
Error: ENOENT: no such file or directory, open '/home/lakecombs/Desktop/Playground/easy_story/backend/views/layouts/main.hbs'
xxxxxxxxxx
const express = require('express')
const path = require('path')
**const Handlebars = require('handlebars')**
**const hbs = require('express-handlebars');**
const bodyParser = require('body-parser');
**const { allowInsecurePrototypeAccess } = require('@handlebars/allow-prototype-access');**
const employeeController = require('./controller/employeeController')
const app = express()
app.use(bodyParser.urlencoded({ extended: true }))
app.use(bodyParser.json())
app.set('views', path.join(__dirname, '/views/'))
app.engine('hbs', hbs({ extname: 'hbs', defaultLayout: 'mainLayout', layoutsDir: __dirname + '/views/layouts/', **handlebars: allowInsecurePrototypeAccess(Handlebars)** }))
app.set('view engine', 'hbs')
app.listen(3000, () => {
console.log('Server started at port 3000')
})
app.use(employeeController)
xxxxxxxxxx
import express from 'express';
import { engine } from 'express-handlebars';
const app = express();
app.engine('handlebars', engine());
app.set('view engine', 'handlebars');
app.set('views', './views');
app.get('/', (req, res) => {
res.render('home');
});
app.listen(3000);
/*
Directory Structure should look something like this
.
├── server.js (current file)
└── views
├── home.handlebars
└── layouts
└── main.handlebars
*/
xxxxxxxxxx
//To output raw HTML instead of escaped HTML use three curly braces instead of two.
//For example:
{{{strong}}}
// Will output the raw HTML from the helper:
strong: function(text) {
return '<strong>' + text + '</strong>';
}
xxxxxxxxxx
router.get('/list', (req, res) => {
Employee.find((err, docs) => {
if (!err) {
res.render("employee/list", {
list: docs,
});
}
else {
console.log('Error in retrieving employee list :' + err);
}
})**.lean()**; // It is prevent the warning when trying to display records