You can create a temporary parent node, and get the innerHTML content of it:

var el = document.createElement("p");
el.appendChild(document.createTextNode("Test"));

var tmp = document.createElement("div");
tmp.appendChild(el);
console.log(tmp.innerHTML); // <p>Test</p>

EDIT: Please see answer below about outerHTML. el.outerHTML should be all that is needed.

Answer from Christian C. Salvadó on Stack Overflow
🌐
W3Schools
w3schools.com › nodejs › met_buffer_tostring.asp
Node.js buffer toString() Method
Node Frameworks Express.js Middleware Concept REST API Design API Authentication Node.js with Frontend
🌐
Toptal
toptal.com › external-blogs › adeva › convert-node-js-buffer-to-string
How to Convert Node.js Buffer to String | Toptal®
May 26, 2026 - The Buffer class uses UTF-8 by default when converting to/from strings, but you can also choose another one from a small set of supported encodings: const b = Buffer.from([101, 120, 97, 109, 112, 108, 101]); console.log(b.toString('latin1')); // example · In most cases, UTF-8 is the best option for both reading and writing. Here is the full list of encodings supported by Node.js as of September/2021 (names are not case sensitive):
🌐
Node.js
nodejs.org › api › string_decoder.html
String decoder | Node.js v26.7.0 Documentation
The node:string_decoder module provides an API for decoding Buffer objects into strings in a manner that preserves encoded multi-byte UTF-8 and UTF-16 characters.
🌐
Bun
bun.sh › guides › streams › node-readable-to-string
Convert a Node.js Readable to a string - Bun
To convert a Node.js Readable stream to a string in Bun, you can create a new Response object with the stream as the body, then use response.text() to read the stream into a string.
Find elsewhere
🌐
Mastering JS
masteringjs.io › tutorials › node › buffer-to-string
Using the Buffer `toString()` Function in Node.js - Mastering JS
August 21, 2020 - Node.js supports numerous different encodings for buffers. The most commonly used are: 'utf8' 'hex' 'base64' For example, by calling .toString('hex'), you get a string representation of the buffer where each byte is encoded as 2 hexadecimal characters. const fs = require('fs'); const buf = fs.readFileSync('./package.json'); buf.toString('hex'); // '7b0a2020...'
🌐
Syncfusion
syncfusion.com › succinctly free ebooks › node.js succinctly › string operations
String Operations | Node.js Succinctly | Syncfusion®
You just add '' and get data with String type automatically. Another solution, you can use toString() method.
🌐
Educative
educative.io › answers › what-is-the-nodejs-buffertostring-method
What is the Node.js Buffer.toString() method?
In Node.js, the Buffer.toString() method is used to decode or convert a buffer to a string, according to the specified character encoding type.
🌐
Actual Wizard
actualwizard.com › actual wizard › programming › javascript › how to convert an html node to a string in javascript
How to Convert an HTML Node to a String in JavaScript - Actual Wizard
October 5, 2020 - In most cases, you will likely want to use the outerHTML method on the node that your code has selected. OuterHTML includes the tag of the node itself, whereas the innerHTML method does not. ... <!DOCTYPE html> <html lang="en"> <head> <meta content="text/html;charset=utf-8" http-equiv="Content-Type"> <meta content="utf-8" http-equiv="encoding"> <title>Extract HTML with JS - getElementById()</title> </head> <body> <div id="test123"> <ul> <li>Example Element One</li> <li>Example Element Two</li> <li>Example Element Three</li> </ul> </div> <script> var MyNode = document.getElementById("test123"); var MyNodeHTML = MyNode.outerHTML; console.log(MyNodeHTML); </script> </body> </html>
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Object › toString
Object.prototype.toString() - JavaScript - MDN Web Docs
The toString() method of Object instances returns a string representing this object. This method is meant to be overridden by derived objects for custom type coercion logic.
🌐
npm
npmjs.com › package › string
string - npm
October 11, 2016 - string contains methods that aren't included in the vanilla JavaScript string such as escaping html, decoding html entities, stripping tags, etc.. Latest version: 3.3.3, last published: 10 years ago. Start using string in your project by running `npm i string`. There are 1042 other projects in the npm registry using string.
      » npm install string
    
Published: Oct 11, 2016
Version: 3.3.3
🌐
GitHub
github.com › supercharge › strings
GitHub - supercharge/strings: String utilities for Node.js · GitHub
... Find all the details for ... @supercharge/strings is pretty straightforward. Pass a string to the imported Function and chain your desired methods to transform to string value to your needs....
Starred by 44 users
Forked by 17 users
Languages: JavaScript 50.0% | TypeScript 50.0%
🌐
Bun
bun.com › guides › streams › readable to string
Convert a Node.js Readable to a string | Bun Guides
To convert a Node.js Readable stream to a string in Bun, create a Response with the stream as the body, then call response.text().