
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
A Node.js framework agnostic library for handlebars template engine
npm install node-hbs handlebars
An example with Hono and complete code is available in example.
import { serve } from "@hono/node-server";
import { Hono } from "hono";
import { NodeHbs } from "node-hbs";
import { join } from "node:path";
const hbs = new NodeHbs({
viewsPath: join(import.meta.dirname, "..", "views"),
});
const app = new Hono();
app.get("/", (c) => {
return c.html(hbs.render("home", { title: "..." }));
});
serve(app);
This library can be used in any Node.js application.
.hbs.layoutName in render method. e.g hbs.render("home", data, "myLayout")viewsPath: Absolute Path to views folder (required)partialsPath: Absolute Path to partials folder (default: views/partials)layoutsPath: Absolute Path to layouts folder (default: views/layouts)defaultLayout: Name of default layout (default: main)externalPartialPaths: List of external partials absolute paths (default: [])render(name: string, data: HbsData = {}, layoutName: string | null = defaultLayout): string - Render page with handlebars dataregisterHelper(name: string, fn: (...args: any[]) => any): void - Register handlebars helperregisterPartial(path: string): void - Register handlebars partialgetRegisteredPartialNames(): Array<{ path: string, name: string }> - Get registered partial names and absolute paths├── src
│ └── index.ts
└── views
├── layouts
│ └── main.hbs
├── partials
│ └── footer.hbs
└── home.hbs
The default layout is main.hbs. You can change the layout for each page by passing layoutName in render method. e.g hbs.render("home", data, "myLayout"). To change the default layout, pass defaultLayout in constructor. e.g new NodeHbs({ defaultLayout: "myLayout" })
Whenever you create a layout make sure it has mainSlot in it.
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Example</title>
<script src="https://cdn.tailwindcss.com"></script>
</head>
<body class="bg-gray-100">
<main class="container mx-auto py-4">{{{ mainSlot }}}</main>
</body>
</html>
The partials are loaded from partials folder. You can also add partials by calling registerPartial method. e.g hbs.registerPartial(join(import.meta.dirname, "..", "node_modules" , "package"))
The registerPartial will load all the partials from the path supplied and if these are folders then will be loaded recursively for all hbs files and register them.
All the partials are registered with the name of the partial file. Please ensure the name are distinct.
The views are loaded from the root of views folder.
FAQs
A Node.js framework agnostic library for handlebars template engine
We found that node-hbs demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.