DEV Community

adityanugroho09
adityanugroho09

Posted on

Error: Missing helper: "handlebars": Missing helper: "handlebars". Any thought ?

📁 server.js

const Hapi = require('@hapi/hapi');
const Inert = require('@hapi/inert');
const Vision = require('@hapi/vision');
const Handlebars = require('handlebars');
const path = require('path');
const routes = require('./routes');

const init = async () => {

  // BUILD SERVER
  const server = Hapi.Server({
    host: 'localhost',
    port: 1234,
    routes: {
      files: {
        relativeTo: path.join(__dirname, 'static'),
      },
    },
  });

  // PLUGIN CONFIGURATION
  await server.register([
    {
      plugin: require('hapi-geo-locate'),
      options: {
      // to able track the user ip
        enabledByDefault: true,
      },
    },
    {
      plugin: Inert,
    },
    {
      plugin: Vision,
    },
  ]);

  // MAKE HANDLEBARS AVAILABLE
  server.views({
    engines: {
      html: Handlebars,
    },
    path: path.join(__dirname, 'views'),
  });

  // ROUTE
  server.route(routes);

  // SERVER CONFIGURATION
  await server.start();
};

init();
Enter fullscreen mode Exit fullscreen mode

📁 routes.js

const {servingDynmaicPage} = require('./handler');
const routes = [
{
  method: 'GET',
  path: '/dynamicPage',
  handler: servingDynmaicPage,
},];

module.exports = routes;
Enter fullscreen mode Exit fullscreen mode

📁 handler.js

const servingDynmaicPage = (request, h) => {
  const data = {name: 'Adit'};
  return h.view('index', data);
};

module.exports = {servingDynmaicPage};
Enter fullscreen mode Exit fullscreen mode

why i get an error like this => Error: Missing helper: "handlebars": Missing helper: "handlebars". Any thought ?

Top comments (0)