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'.

Answer from mscdex on Stack Overflow
🌐
Node.js
nodejs.org › api › buffer.html
Buffer | Node.js v26.10.0 Documentation
Many web pages and other document formats use UTF-8. This is the default character encoding. When decoding a Buffer into a string that does not exclusively contain valid UTF-8 data, the Unicode replacement character U+FFFD � will be used to represent those errors.
🌐
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.
🌐
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.
🌐
Medium
medium.com › @ryan_forrester_ › buffer-to-string-in-javascript-how-to-guide-b24027575419
Buffer to String in JavaScript (How To Guide) | by ryan | Medium
January 7, 2025 - The buffer is created with utf8 encoding. The buffer is then converted to a hexadecimal string using the toString method with 'hex' encoding.
🌐
GeeksforGeeks
geeksforgeeks.org › node-js-buffer-tostring-method
Node.js Buffer.toString() Method | GeeksforGeeks
October 13, 2021 - end: The last index of the buffer data up to which encoding has to be done. Its default value is Buffer.length. Return Value: It returns decoded string from buffer to string according to specified character 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.
🌐
Toptal
toptal.com › external-blogs › adeva › convert-node-js-buffer-to-string
How to Convert Node.js Buffer to String | Toptal®
May 26, 2026 - In a nutshell, it’s easy to convert a Buffer object to a string using the toString() method. You’ll usually want the default UTF-8 encoding, but it’s possible to indicate a different encoding if needed.
🌐
Medium
medium.com › hackernoon › https-medium-com-amanhimself-converting-a-buffer-to-json-and-utf8-strings-in-nodejs-2150b1e3de57
Converting a Buffer to JSON and Utf8 Strings in Nodejs | by Aman Mittal | HackerNoon.com | Medium
April 1, 2019 - Also, it by defaults converts to a utf-8 format string. The other way to convert a buffer to a string is using StringDecoder core module from Nodejs API.
Find elsewhere
🌐
Readthedocs
node.readthedocs.io › en › latest › api › buffer
Buffer - node - Read the Docs
The Buffer class is a global, making it very rare that one would need to ever require('buffer'). Converting between Buffers and JavaScript string objects requires an explicit encoding method.
🌐
TutorialsPoint
tutorialspoint.com › nodejs › nodejs_buffer_tostring_method.htm
Node.js - Buffer.toString() Method
The NodeJS Buffer.toString() method helps to decode the string as per the encoding given. By default, the encoding used is 'utf-8'. Following is the syntax of the Node.JS Buffer.toString() Method − This method accepts three parameters but all are
🌐
GitHub
github.com › node-fetch › node-fetch › issues › 1218
[Japanese encoding] convert buffer to string in correct encoding · Issue #1218 · node-fetch/node-fetch
July 22, 2021 - After look at code of function async text(). i saw that the problem is toString function that will convert buffer to string with encoding is UTF-8.
Author: node-fetch
🌐
Bun
bun.sh › binary data › convert a buffer to a string
Convert a Buffer to a string - Bun
August 4, 2026 - The Buffer class provides a .toString() method that converts a Buffer to a string. const buf = Buffer.from("hello"); const str = buf.toString(); // => "hello" You can optionally specify an encoding and byte range. const buf = Buffer.from("hello ...
🌐
University of New Brunswick
cs.unb.ca › ~bremner › teaching › cs2613 › books › nodejs-api › buffer
buffer
Many web pages and other document formats use UTF-8. This is the default character encoding. When decoding a Buffer into a string that does not exclusively contain valid UTF-8 data, the Unicode replacement character U+FFFD � will be used to represent those errors.
Top answer
1 of 2
319

Single Buffer

If you have a single Buffer you can use its toString method that will convert all or part of the binary contents to a string using a specific encoding. It defaults to utf8 if you don't provide a parameter, but I've explicitly set the encoding in this example.

var req = http.request(reqOptions, function(res) {
    ...

    res.on('data', function(chunk) {
        var textChunk = chunk.toString('utf8');
        // process utf8 text chunk
    });
});

Streamed Buffers

If you have streamed buffers like in the question above where the first byte of a multi-byte UTF8-character may be contained in the first Buffer (chunk) and the second byte in the second Buffer then you should use a StringDecoder. :

var StringDecoder = require('string_decoder').StringDecoder;

var req = http.request(reqOptions, function(res) {
    ...
    var decoder = new StringDecoder('utf8');

    res.on('data', function(chunk) {
        var textChunk = decoder.write(chunk);
        // process utf8 text chunk
    });
});

This way bytes of incomplete characters are buffered by the StringDecoder until all required bytes were written to the decoder.

2 of 2
-5
var fs = require("fs");

function readFileLineByLine(filename, processline) {
    var stream = fs.createReadStream(filename);
    var s = "";
    stream.on("data", function(data) {
        s += data.toString('utf8');
        var lines = s.split("\n");
        for (var i = 0; i < lines.length - 1; i++)
            processline(lines[i]);
        s = lines[lines.length - 1];
    });

    stream.on("end",function() {
        var lines = s.split("\n");
        for (var i = 0; i < lines.length; i++)
            processline(lines[i]);
    });
}

var linenumber = 0;
readFileLineByLine(filename, function(line) {
    console.log(++linenumber + " -- " + line);
});
🌐
freeCodeCamp
freecodecamp.org › news › node-js-buffer-explained
Node.js Buffer Explained
February 17, 2020 - .toString() by default converts a buffer to a utf-8 format string. This is how you decode a buffer. If you specify an encoding you can convert the buffer to another encoding
🌐
W3Resource
w3resource.com › node.js › nodejs-buffer.php
Using Buffers in Node.js - w3resource<
November 13, 2023 - In the above example, the first argument to buffer.write is the string ("Node.js") to write to the buffer, and the second argument is the string encoding ("utf8"). In this case, second argument is not mandatory as "utf8" is the default encoding. str1.write has returned 7, i.e.
🌐
DEV Community
dev.to › melvin2016 › how-to-convert-a-string-to-buffer-and-vice-versa-in-node-js-5op
How to convert a String to Buffer and vice versa in Node.js - DEV Community
September 19, 2020 - The method accepts a valid string as the first argument. ... To convert a Buffer to a String, you can use the toString() in the Buffer object.
🌐
Bun
bun.com › guides › binary data › buffer to string
Convert a Buffer to a string | Bun Guides
The Buffer class provides a .toString() method that converts a Buffer to a string. const buf = Buffer.from("hello"); const str = buf.toString(); // => "hello" You can optionally specify an encoding and byte range. const buf = Buffer.from("hello ...