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
🌐
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.
🌐
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):
🌐
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.
🌐
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...'
Find elsewhere
🌐
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.
🌐
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>
🌐
Webslesson
webslesson.info › 2023 › 08 › how-to-convert-array-to-string-in-nodejs.html
How to convert Array to String in Node.js | Webslesson
August 18, 2023 - If you're dealing with more complex data, JSON.stringify() can be invaluable. Lastly, custom formatting with map() and join() provides flexibility for specific output formats. Remember to consider your use case and the desired format of the output when choosing the appropriate method for converting arrays to strings in your Node.js applications.
🌐
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.
🌐
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