Registry / http-networking / html-element

html-element

JSON →
library2.3.1jsnpmunverified

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.

npm install html-element
INSTALL
IMPORT
SIG · HTML-ELEMENT
H
html-element
http-networkingjavascriptv2.3.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Element
import { Element } from 'html-element';
const Element = require('html-element').Element;
For non-global usage, import named exports directly since v2.
document
const document = require('html-element').document;
import { document } from 'html-element';
The 'document' object is exposed as a property of the main CommonJS export. It is not a named ESM export.
Global Shim
require('html-element/global-shim'); // Creates global document, Element, etc.
require('html-element'); // In v2+, this does NOT create globals.
To restore v1 global behavior, explicitly require the global-shim since v2.0.0.

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> */
Debug
Known issues
breakingThe package no longer affects the global namespace by default. `require('html-element')` will not create global `document` or `Element` objects.
fix
If you rely on global objects, change `require('html-element')` to `require('html-element/global-shim')`. For non-global usage, import objects directly: `const { document } = require('html-element');` or `import { Element } from 'html-element';`
affects: >=2.0.0
breakingAttribute handling was improved in v2.1.0 to distinguish more realistically between IDL (HTML properties like `htmlFor`) and Content attributes (HTML attributes like `for`). HTML output no longer reflects arbitrary properties into attributes.
fix
Review code that sets properties expecting them to always reflect as HTML attributes. Use `setAttribute()` for explicit HTML attributes.
affects: >=2.1.0
gotchaNode.js 4.2 LTS or higher is required. Older Node.js versions will not be supported.
fix
Ensure your Node.js environment is version 4.2 or newer.
affects: >=2.1.0
gotcha`Node.insertBefore()` now correctly appends a new node if its `referenceNode` argument is `null`, aligning with DOM API specifications.
fix
No fix needed, but be aware of this behavior change if your code previously relied on `insertBefore(newNode, null)` *not* appending.
affects: >=2.2.0
gotchaThe `textContent` property can now be set on `Element` nodes, which removes all existing children and replaces them with a single text node.
fix
No fix needed, but be aware that setting `textContent` will overwrite existing child nodes.
affects: >=2.2.0
gotcha`Element` instances now expose a `tagName` property, which returns the uppercase tag name of the element.
fix
Update any code that previously tried to infer the tag name from other properties or lacked this capability.
affects: >=2.2.0
Errors
Common errors & fixes
ReferenceError: document is not defined
Attempting to access `document` global after upgrading from `html-element` v1 to v2 without adjusting import statements.
fix
If you need a global `document` object, change your import to `require('html-element/global-shim');`. Otherwise, import `document` explicitly: `const { document } = require('html-element');`
TypeError: Cannot read property 'createElement' of undefined
The main `html-element` export was `require()`d, but `document` was not accessed as a property, or the wrong import method was used for `document`.
fix
Ensure you are accessing `document` correctly: `const { document } = require('html-element');` or `const document = require('html-element').document;`.
Upgrade
Version history
2.3.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
html-element — npm install html-element · libregistry