UCS-2 is a character encoding standard in which characters are represented by a fixed-length 16 bits (2 bytes)

With the encoding known you can decode properly and get the data as expected:

const data = [79, 0, 98, 0, 115, 0, 116, 0, 59, 0, 80, 0, 101, 0, 114, 0, 115, 0, 111, 0, 110, 0, 59, 0]
const dataBuffer = Buffer.from(data)
const utf16Decoder = new TextDecoder('UTF-16')

console.log(utf16Decoder.decode(dataBuffer)) // Obst;Person;

I think it's trying to decode as utf8 by default and getting upset at the unrenderable null bytes between every character:

Answer from Gavin on Stack Overflow
🌐
W3Schools
w3schools.com › nodejs › met_buffer_tostring.asp
Node.js buffer toString() Method
Node.js Compiler Node.js Server Node.js Quiz Node.js Exercises Node.js Pratice Problems Node.js Syllabus Node.js Study Plan ... The toString() method returns the buffer object according to the specified encoding.
Discussions

node.js - Javascript - How to convert buffer to a string? - Stack Overflow
This doesn't really replies the question. I know it's already string, but he needs to do as the best answer states (Convert from the Buffer-string-like representation to string). More on stackoverflow.com
🌐 stackoverflow.com
July 3, 2019
node.js - Convert buffer to readable string javascript - Stack Overflow
I receive a JSON as a buffer. I want to parse it into a readable or JSON object. However, despite all techniques (JSON.stringify(), toString('utf8'), I am not able to get it done. More on stackoverflow.com
🌐 stackoverflow.com
converting buffer to string - javascript
Btw I have no access to data since ... buffer to parse which is not returning the proper result. It is returning "\b Ì jQßô\f:l{Ê­3DZz²ú_¿;t_ ¹ÐÇævËçÕ§MAjHríþ;!/Ýdãi", Can someone help me with what it is that I am doing wrong? ... which is not returning the proper result. So what is the proper result? Those numbers don't look like they'd result in readable ascii. ... @TienDuong I get the buffer as part of the response from fabric node js sdk when I ... More on stackoverflow.com
🌐 stackoverflow.com
node.js - convert streamed buffers to utf8-string - Stack Overflow
I want to make a HTTP-request using node.js to load some text from a webserver. Since the response can contain much text (some Megabytes) I want to process each text chunk separately. I can achieve... More on stackoverflow.com
🌐 stackoverflow.com
🌐
Adeva
adevait.com › nodejs › convert-node-js-buffer-to-string
How to Convert Node.js Buffer to String | Toptal®
May 26, 2026 - The content of a Buffer may be quickly converted to a String using the toString() method:
🌐
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 - A buffer is created from a string using Buffer.from. The buffer is then converted back to a string using the toString method.
🌐
Node.js
nodejs.org › api › buffer.html
Buffer | Node.js v26.10.0 Documentation
Node.js also supports the following binary-to-text encodings. For binary-to-text encodings, the naming convention is reversed: Converting a Buffer into a string is typically referred to as encoding, and converting a string into a Buffer as decoding.
🌐
Daniel Lemire's blog
lemire.me › blog › 2023 › 12 › 08 › fast-buffer-to-string-conversion-in-javascript-with-a-lookup-table
Fast Buffer-to-String conversion in JavaScript with a Lookup Table – Daniel Lemire's blog
December 8, 2023 - When programming in a JavaScript environment such as Node.js, you might recover raw data from the network and need to convert the bytes into strings. In a system such as Node.js, you may represent such raw bytes using a Buffer instance. You can conveniently convert a Buffer instance into a JavaScript (mybuffer.toString()). But, maybe surprisingly, … Continue reading Fast Buffer-to-String conversion in JavaScript with a Lookup Table
🌐
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.
Find elsewhere
🌐
Mastering JS
masteringjs.io › tutorials › node › buffer-to-string
Using the Buffer `toString()` Function in Node.js - Mastering JS
August 21, 2020 - For example, if you create a buffer from a string using Buffer.from(), the toString() function gives you the original string back. const buf = Buffer.from('Hello, World', 'utf8'); buf.toString(); // 'Hello, World' The toString() method's first ...
🌐
Melvin George
melvingeorge.me › blog › convert-string-buffer-nodejs
How to convert a String to Buffer and vice versa in Node.js | MELVIN GEORGE
September 19, 2020 - // buffer const str = "Hey. this is a string!"; const buff = Buffer.from(str, "utf-8"); // convert buffer to string const resultStr = buff.toString(); console.log(resultStr); //Hey.
🌐
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.
🌐
GeeksforGeeks
geeksforgeeks.org › node-js-buffer-tostring-method
Node.js Buffer.toString() Method | GeeksforGeeks
October 13, 2021 - Example 1: ... // Node.js program to demonstrate the // Buffer.toString() Method // Creating a buffer var buffer = new Buffer.alloc(5); // Loop to add value to the buffer for (var i = 0; i < 5; i++) { buffer[i] = i + 97; } // Display the value ...
🌐
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.
🌐
Joshtronic
joshtronic.com › 2022 › 11 › 27 › convert-a-buffer-to-a-string-in-nodejs
Convert a buffer to a string in Node.js - Joshtronic
November 27, 2022 - While we already know what the buffer contains, since we defined the string, let's take a look at what the buffer looks like, so we can get a sense for how things would look when we don't know what the buffer contains: console.log(buffer); // <Buffer 49 20 61 6d 20 61 20 62 75 66 66 65 72 21> The buffer is effectively just an array of integers that represent the data that it contains. To get a string back out of the buffer, simply use .toString():
🌐
Milddev
milddev.com › converting-javascript-buffers-to-strings
JavaScript Buffer to String Conversion
July 4, 2025 - For strict JSON handling, remember that JSON.stringify() produces a stringified Buffer but won’t include the raw bytes. To embed binary, use base64 and decode on the other side. Converting large Buffers repeatedly can block your event loop.
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);
});