How to Setup Handlebars View Engine in Node.js ? Last Updated : 27 Apr, 2020 Comments Improve Suggest changes Like Article Like Report Handlebars is a template engine that is widely used and easy to use. The pages contain .hbs extension and there are many other template engines in the market like EJS, Mustache, etc. Installation of hbs module: You can visit the link Install hbs module. You can install this package by using this command. npm install hbs After installing hbs module, you can check your hbs version in command prompt using the command. npm version hbs After that, you can just create a folder and add a file for example index.js, To run this file you need to run the following command. node index.js To setup hbs view engine, you need to write this middleware in your index.js as follow: app.set('views', path.join(__dirname)) app.set('view engine', 'hbs') Now create the file and run the code. It will display the result. Filename: Home.hbs html <!DOCTYPE html> <html> <head> <title>Handlebars Demo</title> </head> <body> <!-- For loop demo --> {{#each array}} <h4>{{this}}</h4> {{/each}} <h4>{{message}}</h4> </body> </html> Filename: index.js javascript const express = require('express') const path = require('path') const hbs = require('hbs') const app = express() // View Engine Setup app.set('views', path.join(__dirname)) app.set('view engine', 'hbs') app.get('/', function(req, res){ res.render('Home', { array: ['One', 'Two', 'Three', 'Four'], message: 'Greetings from geekforgeeks' }) }) app.listen(8080, function(error){ if(error) throw error console.log("Server created Successfully") }) Steps to run the program: The project structure will look like this: Make sure you have installed hbs and express module using the following commands: npm install hbs npm install express Run index.js file using the following command: node index.js Open browser and type this URL: http://localhost:8080/. Then you will see the Home.hbs page as shown below: So this is how you can setup Handlebars (hbs) view engine in node.js. There are many other handlebars engines exist like EJS, Mustache, etc. Comment More infoAdvertise with us Next Article How to Setup Handlebars View Engine in Node.js ? G gouravhammad Follow Improve Article Tags : JavaScript Web Technologies Node.js Write From Home Node.js-Misc +1 More Similar Reads How to Setup View Engine in Node.js ? View engines are useful for rendering web pages. There are many view engines available in the market like Mustache, Handlebars, EJS, etc but the most popular among them is EJS which simply stands for Embedded JavaScript. It is a simple templating language/engine that lets its user generate HTML with 2 min read How to Display Images using Handlebars in Node.js ? In this article, we will discuss how to display images using handlebars in Node.js. You may refer to this article for setting up handlebars View Engine in Node.jsApproachTo display images using Handlebars in Node.js, pass the image URLs to the template from your server. In the Handlebars template, u 3 min read How to include CSS files in EJS View Engine? Including CSS files is important for styling web pages in web development with Node.js, Express, and EJS. In this article, we will explore the process of including CSS in such projects to enhance the visual appeal and user experience. Approach to include CSS file in EJS:We're building a Node.js web 3 min read How to use Template Engines in Express JS ? Express.js is a popular web framework for Node.js that simplifies the process of building web applications. One of the key features of Express is its ability to integrate with template engines, allowing developers to dynamically generate HTML pages with data from their server. In this article, we'll 3 min read How to separate Handlebars HTML into multiple files / sections using Node.js ? In this article, we will learn about separating Handlebars HTML into multiple files/sections using Node.js and using it on any page that you want. It helps in reducing the repetition of code. For example, instead of adding the whole navbar on each page, you can just make a template of that navbar an 3 min read Like