# @gboutte/nestjs-hbs

> This package provide a service to render handlebars templates for nestjs.

Latest version **0.2.0** (published 2025-07-31) · MIT license · 0 weekly downloads

## Install

```sh
npm install @gboutte/nestjs-hbs
pnpm add @gboutte/nestjs-hbs
yarn add @gboutte/nestjs-hbs
bun add @gboutte/nestjs-hbs
```

## Health

**Score 50/100 (C)** — status: stable.

Positive: has types; no vulnerabilities; high maintenance score; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: stale.

## Facts

| | |
|---|---|
| Version | 0.2.0 |
| Published | 2025-07-31 |
| First published | 2022-10-25 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 532.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | Grégory Boutte |
| Maintainers | gboutte |
| Keywords | nestjs, handlebars, hbs, templates |

## Links

- npm: https://www.npmjs.com/package/@gboutte/nestjs-hbs
- Repository: https://github.com/gboutte/nestjs-hbs
- Homepage: https://github.com/gboutte/nestjs-hbs#readme
- Issues: https://github.com/gboutte/nestjs-hbs/issues
- npm.io page: https://npm.io/package/@gboutte/nestjs-hbs

## Recent versions

- 0.2.0 (latest) — 2025-07-31
- 0.1.0 — 2025-06-14
- 0.0.15 — 2023-08-25
- 0.0.14 — 2023-08-25
- 0.0.13 — 2023-08-25
- 0.0.12 — 2023-08-15
- 0.0.11 — 2023-03-11
- 0.0.10 — 2023-03-11
- 0.0.9 — 2023-03-11
- 0.0.8 — 2023-01-15
- 0.0.7 — 2023-01-14
- 0.0.6 — 2023-01-14
- 0.0.5 — 2023-01-01
- 0.0.4 — 2022-11-03
- 0.0.3 — 2022-10-30
- … 2 more at https://npm.io/package/@gboutte/nestjs-hbs/versions

## README

# Installation

```shell
npm install @gboutte/nestjs-hbs
```

# Configuration

```ts
@Module({
  imports: [
    HandlebarsModule.forRoot({
      templateDirectory: 'templates',
      partialDirectory: 'templates/partials',
      compileOptions: {},
      templateOptions: {},
    })
  ],
  controllers: [],
  providers: [],
})
export class AppModule {}
```
|                   | Description                                                                                                                            |
|-------------------|----------------------------------------------------------------------------------------------------------------------------------------|
| `templateDirectory` | This will define the folder where the templates files are located                                                                      |
| `compileOptions`    | The templates options can be found on: https://handlebarsjs.com/api-reference/runtime-options.html#options-to-control-prototype-access |
| `templateOptions`   | The compile options can be found on https://handlebarsjs.com/api-reference/compilation.html#handlebars-compile-template-options        |
| `partialDirectory`   | This will load all files as partials. If you have a file named `myPartial.hbs`, a partial named `myPartial` will be added.               |
| `helpers`   | An array of helpers to add in handlebars, each helpers has a property `name` and  `fn`                                                 |



# Usage


You can use the `HandlebarsService`, there is currently two methods

|            | Description                                                                                                                      | Parameters                                                                                                             |
|------------|----------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------|
| renderFile | This will render a handlebars template (located in the template folder previously defined), and will return the rendered string. | - `file`: the template file to render <br>- `parameters`: an array of parameters that will be used inside the template |
| render     | This will render a template string using handlebars                                                                              | - `html`: the template <br>- `parameters`: an array of parameters that will be used inside the template string         |
Here is an example 
```ts
@Controller()
export class AppController {
  constructor(private readonly hbsService: HandlebarsService) {}

  @Get()
  async getTest() {
    return this.hbsService.renderFile('hello.hbs', { name: 'John Doe'});
  }
  @Get('template-string')
  async getTest() {
    return this.hbsService.render('<h1>Hello {{name}}</h1>', { name: 'John Doe'});
  }
}
```

---
_Source: https://npm.io/package/@gboutte/nestjs-hbs · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
