HTML Element Shim for Server-Side Templating

2.3.1 · abandoned · verified Tue Apr 21

html-element is a server-side shim providing a partial implementation of `HTMLElement` for Node.js environments. It enables client-side templating libraries, such as Hyperscript, to execute server-side without a full browser DOM. The current stable version is 2.3.1, released in August 2016. The project appears to be in an abandoned state with no significant updates since 2017, making its release cadence non-existent. Its primary differentiation is its lightweight nature, offering just enough DOM API to render templates without the overhead of a headless browser, focusing on core element creation, manipulation, and serialization methods like `createElement`, `appendChild`, `setAttribute`, and `toString()`. It supports Node.js versions 4.2 and higher.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates basic usage of `html-element` to create a document, elements, set attributes and text content, then render to HTML string.

const { document } = require('html-element');

const body = document.createElement('body');
const div = document.createElement('div');
div.setAttribute('id', 'container');
div.setAttribute('class', 'wrapper');
div.textContent = 'Hello, html-element!';

const h1 = document.createElement('h1');
h1.textContent = 'Page Title';

body.appendChild(h1);
body.appendChild(div);

const renderedHtml = body.toString();
console.log(renderedHtml);
/* Expected output:
<body><h1>Page Title</h1><div id="container" class="wrapper">Hello, html-element!</div></body>
*/

view raw JSON →