Typeerror: Server.views Is Not A Function In Hapi.js
I am a beginner on node.js I am using hapi framework for my web app. In that i am using handlebars for template. When i configure the server views i am getting the type error.
Solution 1:
For making use of server.views
, you would need the Vision plugin
e.g. with Handlebars
const server = newHapi.Server();
server.connection({ port: 8000 });
const handler = function (request, reply) {
reply.view('basic/index', {
title: 'examples/views/handlebars/basic.js | Hapi ' + request.server.version,
message: 'Hello World!'
});
};
server.register(require('vision'), (err) => {
if (err) {
throw err;
}
server.views({
engines: { html: require('handlebars') },
path: __dirname + '/templates'
});
server.route({ method: 'GET', path: '/', handler: handler });
});
Post a Comment for "Typeerror: Server.views Is Not A Function In Hapi.js"