# polka-ejs

> Adds EJS (Embedded JavaScript) template engine support to polka

Latest version **1.0.1** (published 2024-02-20) · MIT license · 0 weekly downloads

## Install

```sh
npm install polka-ejs
pnpm add polka-ejs
yarn add polka-ejs
bun add polka-ejs
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2024-02-20 |
| First published | 2018-10-11 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 4.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 4 |
| Author | Ravener |
| Maintainers | ravener |
| Keywords | ejs, polka, embedded, javascript, middleware |

## Links

- npm: https://www.npmjs.com/package/polka-ejs
- Repository: https://github.com/ravener/polka-ejs
- Homepage: https://github.com/ravener/polka-ejs#readme
- Issues: https://github.com/ravener/polka-ejs/issues
- npm.io page: https://npm.io/package/polka-ejs

## Dependencies (1)

- [ejs](https://npm.io/package/ejs.md) ^3.1.9

## Alternatives

- [@sindresorhus/slugify](https://npm.io/package/@sindresorhus/slugify.md) — 3.7M weekly downloads
- [solid-js](https://npm.io/package/solid-js.md) — 2.7M weekly downloads
- [expo-glass-effect](https://npm.io/package/expo-glass-effect.md) — 2.5M weekly downloads
- [nanoassert](https://npm.io/package/nanoassert.md) — 780.8K weekly downloads
- [@ffmpeg/ffmpeg](https://npm.io/package/@ffmpeg/ffmpeg.md) — 529.5K weekly downloads

## Recent versions

- 1.0.1 (latest) — 2024-02-20
- 1.0.0 — 2018-10-11

## README

# Polka EJS
Adds [ejs](https://ejs.co) template engine support to [polka](https://github.com/lukeed/polka)

## Install

```sh
npm install polka-ejs
```

## Usage

```js
const polka = require("polka");
const ejs = require("polka-ejs");

const app = polka();

app.use(ejs());

app.get("/", (req, res) => {
  res.render("index.ejs", { number: 5 });
});

app.listen(3000);
```

Create a `views/index.ejs` with the following

```html
<html>
  <body>
    <h1>The Number is <%= number %></h1>
  </body>
</html>
```

Now visiting `http://localhost:3000` will display the number `5` on the page!

## Options
All options with their default values.

```js
app.use(ejs({
  views: path.join(process.cwd(), "views"),
  cache: process.env.NODE_ENV === "production",
  contentType: "text/html",
  status: 200,
  ext: "ejs",
  options: {}
}));
```

Options can be overriden per call basis aswell

```js
res.render("index", {
  views: path.join(__dirname, "secretViewsJustForThisRoute"),
  status: 500,
  contentType: "text/html",
  cache: false,
  ext: "html",
  options: {}
});
```

Few things to note

- ext is used if the extension is not provided in the render call, i.e lets you make views/index.html and if ext is set to `html` just `res.render("index")` is enough.
- Cache uses the simple in memory cache that comes with ejs to override this `require()` ejs and change the value of `ejs.cache` like examples in their readme
- Could possibly work with other frameworks if they have a similar style of middleware but i haven't seen any.

## License
MIT

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