From a7bea39b2d9064dccc16d1a889d8c7a01bccc768 Mon Sep 17 00:00:00 2001 From: neeraj-2 <56186425+neeraj-2@users.noreply.github.com> Date: Tue, 4 Aug 2020 12:10:27 +0530 Subject: [PATCH] Updated There was a problem that i faced .I was not able to see data(full name,email,mobile,city)in" view all" field .But still data was present in my database in mongoDB compass. I found that i should install package by command "npm install @handlebars/allow-prototype-access" and should add above modification i.e 1.const Handlebars = require('handlebars') 2.const {allowInsecurePrototypeAccess} = require('@handlebars/allow-prototype-access') and instead 3.app.engine('hbs', exphbs({ extname: 'hbs', defaultLayout: 'mainLayout', layoutsDir: __dirname + '/views/layouts/' })); use: 4.app.engine('hbs', exphbs({ extname: 'hbs', handlebars: allowInsecurePrototypeAccess(Handlebars), defaultLayout: 'mainlayout', layoutsDir: __dirname + '/views/layouts/' })); will solve the problem and data can be seen in require field on browser...local host whatever u are using --- project/server.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/project/server.js b/project/server.js index 2a78978b..47513018 100644 --- a/project/server.js +++ b/project/server.js @@ -4,7 +4,11 @@ const express = require('express'); const path = require('path'); const exphbs = require('express-handlebars'); const bodyparser = require('body-parser'); +//to add if on view all we can not see the data +const Handlebars = require('handlebars') +const {allowInsecurePrototypeAccess} = require('@handlebars/allow-prototype-access') +// const employeeController = require('./controllers/employeeController'); var app = express(); @@ -13,11 +17,14 @@ app.use(bodyparser.urlencoded({ })); app.use(bodyparser.json()); app.set('views', path.join(__dirname, '/views/')); -app.engine('hbs', exphbs({ extname: 'hbs', defaultLayout: 'mainLayout', layoutsDir: __dirname + '/views/layouts/' })); +//app.engine('hbs', exphbs({ extname: 'hbs', defaultLayout: 'mainLayout', layoutsDir: __dirname + '/views/layouts/' })); +//this instead previous one +app.engine('hbs', exphbs({ extname: 'hbs', handlebars: allowInsecurePrototypeAccess(Handlebars), defaultLayout: 'mainlayout', layoutsDir: __dirname + '/views/layouts/' })); + app.set('view engine', 'hbs'); app.listen(3000, () => { console.log('Express server started at port : 3000'); }); -app.use('/employee', employeeController); \ No newline at end of file +app.use('/employee', employeeController);