giterman

1.1.1 • Public • Published

Logo

⚪ About the package ⚪

This package offers a very simple HTML template engine.
The goal of this package is to replace certain text of your HTML markup with text chosen from your Node.js backend application.

Happy coding!

⬜ Get started ⬜

const renderHTML = require("giterman")

const finalHTML = renderHTML("./index.html", {firstName: "rani", lastName: "giterman"})

🤍 Installation 🤍

$ npm i giterman

Documentation

You can call the main function with whatever name you'd like. As long as you install the package and require it in your code.

The main function receives two paramaters. First one being pathFile and second one being fields.

  • pathFile

    - The path to the HTML file.
  • fields

    - An object documenting the text being replaced inside the HTML file. Each key stands for the field's name inside the HTML, and it's value is the text which the HTML will be replaced with.

Example

Example HTML file (index.html):

  <!DOCTYPE html>
  <html lang="en">
    <head>
      <meta charset="UTF-8" />
      <meta http-equiv="X-UA-Compatible" content="IE=edge" />
      <meta name="viewport" content="width=device-width, initial-scale=1.0" />
      <title>Title</title>
    </head>
    <body>
      <div>{{firstName}} {{lastName}}</div>
    </body>
  </html>

Example node.js express route which will send the HTML:

const express = require("express");
const PORT = 3000
const app = express();

const http = require("http").Server(app);

const renderHTML = require("giterman");

const finalHTML = renderHTML("./index.html", {
  firstName: "rani",
  lastName: "giterman",
});

app.get("/", (req, res) => {
  res.send(finalHTML);
});

http.listen(PORT, () => {
  console.log(`Server listening on ${PORT}`);
});

The result is the following: res

Readme

Keywords

Package Sidebar

Install

npm i giterman

Weekly Downloads

1

Version

1.1.1

License

ISC

Unpacked Size

83.3 kB

Total Files

4

Last publish

Collaborators

  • ranigiterman