Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

html-vars-replacer

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

html-vars-replacer

html vars in {{ }} replacer

  • 1.0.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

html-vars-replacer

This module replaces variables in your HTML to be able to make a more comfortable server side render

Simple example

HTML file

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>{{TITLE}}</title>
    </head>
    <body>
        <p>{{MY_SECOND_VARIABLE}}<p>
    </body>
</html>

Express app endpoint

const express = require('express');
const path = require('path');
const HTMLVarsReplacer = require('html-vars-replacer');
const app = express();

let data = {
    TITLE : "my title",
    MY_SECOND_VARIABLE : "hello world",
};

app.get('/', async function(req, res) {
    let strPathHTML = path.join(__dirname, '/index.html');
    let strHTMLRendered = await HTMLVarsReplacer(strPathHTML, data);
    res.send(strHTMLRendered);
});

Result:

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>my title</title>
    </head>
    <body>
        <p>hello world<p>
    </body>
</html>

Keywords

FAQs

Package last updated on 12 Oct 2020

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc