
Security News
MCP Community Begins Work on Official MCP Metaregistry
The MCP community is launching an official registry to standardize AI tool discovery and let agents dynamically find and install MCP servers.
node-inject-html
Advanced tools
Fast, lightweight HTML injection via string, for when you don’t have access to the DOM (e.g. Node.js).
⚠️ If you do have access to the DOM, don’t use this! Use
appendChild()
instead.
This library only has 1 dependency: moo, a highly-optimized JS lexer.
npm i node-inject-html
import { inject } from 'node-inject-html';
const html = `<!doctype HTML>
<html>
<head>
<link rel="stylesheet" href="/styles.css" />
</head>
<body>
<div id="app"></div>
</body>
</html>
`;
inject(html, {
headStart: '<script src="https://someanalyticsfunction.com"></script>',
headEnd:
'<link href="https://fonts.googleapis.com/css2?family=Public+Sans:ital,wght@0,400;0,700;1,400;1,700&display=swap" rel="stylesheet">',
bodyStart:
'<noscript>You need JavaScript enabled to run this application.</noscript>',
bodyEnd: '<script async src="./hmr.js"></script>',
});
// <!doctype HTML>
// <html>
// <head>
// <script src="https://someanalyticsfunction.com"></script> <!-- NEW -->
// <link rel="stylesheet" href="/styles.css" />
// <link href="https://fonts.googleapis.com/css2?family=Public+Sans:ital,wght@0,400;0,700;1,400;1,700&display=swap" rel="stylesheet"> <!-- NEW -->
// </head>
// <body>
// <noscript>You need JavaScript enabled to run this application.</noscript> <!-- NEW -->
// <div id="app"></div>
// <script async src="./hmr.js"></script>
// </body>
// </html>
This is a useful tool for SSR or any time you need to scan the DOM without having access to the DOM itself, like in Node.
Yes! This library is lightweight and performant enough you may find it handles better than a heavy DOM parser / AST library.
Yes! Any HTML (but note that malformed HTML will break your app—this won’t validate it!)
No. Try node-html-parser or something.
Yes! Contributions are welcome. Please see CONTRIBUTING.md to get started.
**No!**️ If you are running this in the context of a browser, you should use
appendChild()
instead.
FAQs
Inject any HTML into <head> or
The npm package node-inject-html receives a total of 710 weekly downloads. As such, node-inject-html popularity was classified as not popular.
We found that node-inject-html demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
The MCP community is launching an official registry to standardize AI tool discovery and let agents dynamically find and install MCP servers.
Research
Security News
Socket uncovers an npm Trojan stealing crypto wallets and BullX credentials via obfuscated code and Telegram exfiltration.
Research
Security News
Malicious npm packages posing as developer tools target macOS Cursor IDE users, stealing credentials and modifying files to gain persistent backdoor access.