How to use ejs

Comprehensive ejs code examples:

How to use ejs.clearCache:

95
96
97
98
99
100
101
102
103
let ejs = require('ejs'),
    LRU = require('lru-cache');
ejs.cache = LRU(100); // LRU cache with 100-item limit
```

*If you want to clear the EJS cache, call ejs.clearCache. If you're using the LRU cache and need a different limit, simple reset ejs.cache to a new instance of the LRU.*

### Custom file loader
The default file loader is fs.readFileSync, if you want to customize it, you can set ejs.fileLoader.

How to use ejs.fileLoader:

98
99
100
101
102
103
104
105
106
107
```

*If you want to clear the EJS cache, call ejs.clearCache. If you're using the LRU cache and need a different limit, simple reset ejs.cache to a new instance of the LRU.*

### Custom file loader
The default file loader is fs.readFileSync, if you want to customize it, you can set ejs.fileLoader.

```javascript
let ejs = require('ejs');
let myFileLoad = function (filePath) {

How to use ejs.registerPartials:

33
34
35
36
37
38
39
40
41
42
43
44
app.use(express.urlencoded({ extended: false }));


app.use(express.static(static_path));
app.set("view engine", "ejs");
app.set("views", temp_path);
// ejs.registerPartials(part_path);


app.get("/", (req, res) => {
  var loginUser = localStorage.getItem("loginUser");
  if(loginUser) {

How to use ejs.compile:

27
28
29
30
31
32
33
34
35
36
  options: OptionsI
) {
  const path = join(__dirname, 'views', 'result.ejs');
  const targetPath = join(process.cwd(), '/bba', 'bba');
  const ejsString = ejs.fileLoader(path, 'utf8'),
    template = ejs.compile(ejsString, {
      bundleReport,
      options,
      filename: path,
    }),

How to use ejs.render:

243
244
245
246
247
248
249
250
251
252
```html
<div id="output"></div>
<script src="ejs.min.js"></script>
<script>
  let people = ['geddy', 'neil', 'alex'],
      html = ejs.render('<%= people.join(", "); %>', {people: people});
  // With jQuery:
  $('#output').html(html);
  // Vanilla JS:
  document.getElementById('output').innerHTML = html;

How to use ejs.renderFile:

9
10
11
12
13
14
15
16
17
18
  return fs.readFileSync(path.normalize(path.join(__dirname, '..', filePath)));
};

module.exports = function handleErrors(document) {
  function renderErrorPage(data) {
    ejs.renderFile('error.ejs', data, (err, content) => {
      if (err) {
        // eslint-disable-next-line no-console
        console.error(`Failed to render error page. Error code "${data.errorDescription}".`);
        return;