The official node.js documentation for Buffer is the best place to check for something like this. As previously noted, Buffer currently supports these encodings: 'ascii', 'utf8', 'utf16le'/'ucs2', 'base64', 'base64url', 'latin1'/'binary', and 'hex'.
Top answer 1 of 3
66
The official node.js documentation for Buffer is the best place to check for something like this. As previously noted, Buffer currently supports these encodings: 'ascii', 'utf8', 'utf16le'/'ucs2', 'base64', 'base64url', 'latin1'/'binary', and 'hex'.
2 of 3
23
As is always the way, I spent a while Googling but found nothing until after I posted the question:
http://www.w3resource.com/node.js/nodejs-buffer.php has the answer. You can use the following types in .toString() on a buffer:
asciiutf8utf16leucs2(alias ofutf16le)base64binaryhex
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. Converting a buffer to a string is known as encoding, and converting a string to a buffer is known ...
Node.js
nodejs.org › api › buffer.html
Buffer | Node.js v26.10.0 Documentation
If no character encoding is specified, UTF-8 will be used as the default. import { Buffer } from 'node:buffer'; const buf = Buffer.from('hello world', 'utf8'); console.log(buf.toString('hex')); // Prints: 68656c6c6f20776f726c64 console.log(buf.toString('base64')); // Prints: aGVsbG8gd29ybGQ= ...
Mastering JS
masteringjs.io › tutorials › node › buffer-to-string
Using the Buffer `toString()` Function in Node.js - Mastering JS
August 21, 2020 - By default, toString() converts the buffer to a string using UTF8 encoding.
W3Schools
w3schools.com › nodejs › met_buffer_tostring.asp
Node.js buffer toString() Method
The toString() method returns the buffer object according to the specified encoding.
TutorialsPoint
tutorialspoint.com › nodejs › nodejs_buffer_tostring_method.htm
Node.js - Buffer.toString() Method
By default, the encoding used is 'utf-8'. Following is the syntax of the Node.JS Buffer.toString() Method −
Bun
bun.sh › binary data › convert a buffer to a string
Convert a Buffer to a string - Bun
August 4, 2026 - const buf = Buffer.from("hello"); const str = buf.toString(); // => "hello" You can optionally specify an encoding and byte range. const buf = Buffer.from("hello world!"); const str = buf.toString("utf8", 0, 5); // => "hello" See Binary Data.
Readthedocs
node.readthedocs.io › en › latest › api › buffer
Buffer - node - Read the Docs
If encoding is undefined or null, then encoding defaults to 'utf8'. The start and end parameters default to 0 and buffer.length when undefined. buf = new Buffer(26); for (var i = 0 ; i < 26 ; i++) { buf[i] = i + 97; // 97 is ASCII a } buf.toString('ascii'); // outputs: abcdefghijklmnopqrstuvwxyz ...
GitHub
github.com › oven-sh › bun › issues › 455
Buffer#toString unexpected / incorrect results with encoding · Issue #455 · oven-sh/bun
July 8, 2022 - // node prints [ 65 ] while bun prints [ 65, 209 ] console.log(Buffer.from([65, 0]).toString("utf16le").split("").map(x => x.charCodeAt(0))); NodeJS prints the expected [ 65 ] (one character, 0x41 == 65) but Bun generates two characters [ 65, 209 ] B) base64 encoding does not include padding: // bun and node both print QQA console.log(Buffer.from([65, 0]).toString("base64url")) // node prints QQA= with the padding while bun omits the padding console.log(Buffer.from([65, 0]).toString("base64")) As noted in the NodeJS docs, base64url omits padding while base64 includes padding.
Author: oven-sh
Google Groups
groups.google.com › g › nodejs › c › 89JMthbHCvw
buffer toString with partial utf8 character?
September 3, 2014 - If you want to be sure, you can use StringDecoder#detectIncompleteChar(). It's not documented but it takes a buffer as its argument: var buffer = /* ... */; var StringDecoder = require('string_decoder').StringDecoder; var dec = new StringDecoder('utf8'); dec.detectIncompleteChar(buffer); if (dec.charReceived < dec.charLength) { // Partial character sequence. } You can also implement the algorithm yourself if you don't want to depend on an undocumented function. UTF-8 is a self-synchronizing run-length encoding; you can figure out the length of the character by looking at the last one to three bytes.