You can do:

var buf = Buffer.from(bufStr, 'utf8');

But this is a bit silly, so another suggestion would be to copy the minimal amount of code out of the called function to allow yourself access to the original buffer. This might be quite easy or fairly difficult depending on the details of that library.

Answer from John Zwinck on Stack Overflow
🌐
W3Schools
w3schools.com › nodejs › met_buffer_tostring.asp
Node.js buffer toString() Method
Node Modules Node ES Modules Node NPM Node package.json Node NPM Scripts Node Manage Dep Node Publish Packages · HTTP Module HTTPS Module File System (fs) Path Module OS Module URL Module Events Module Stream Module Buffer Module Crypto Module Timers Module DNS Module Assert Module Util Module Readline Module
Discussions

node.js 6.0.0 buffer to string equivalent in python3
Just don't try to decode at all. Decoding turns bytestrings into text strings, and a hash isn't a text string. kdf_v = bytes.fromhex('E6F8C08930597B47472620568D207A23E4FCEF4B3F0AA3DC26FF369C622C6E1D') gives you a 32-byte bytes object, which is functionally equivalent to a Node.js Buffer. More on stackoverflow.com
🌐 stackoverflow.com
Python equivalent of Node.js Buffer.from('string', 'base64') - Stack Overflow
I'm trying to implement authorization based on a hash-based message authentication code (HMAC)-encrypted authorization header. To do so I need to use the authorization header to verify the authenti... More on stackoverflow.com
🌐 stackoverflow.com
node.js - Nodejs InputStream Buffer convert to string using python - Stack Overflow
i have one application nodejs which request send to python using python-shell npm package. and python script read data and parse string. nodejs file : teststr.js let buf = ` More on stackoverflow.com
🌐 stackoverflow.com
node.js - Buffer to string difference in NodeJs Vs Python - Stack Overflow
I have an incoming buffer whose print to terminal differs between node and python, although both show the same length of 62 1) Python print(in_buffer) b'\x00\x00\x00>\x00\x03\x00\x00user\x00po... More on stackoverflow.com
🌐 stackoverflow.com
April 11, 2020
🌐
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 - To convert a string to a Buffer, you can use the from() method from the global Buffer class in Node.js.
🌐
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 - To convert a string to a Buffer, you can use the from() method from the global Buffer class in Node.js.
🌐
Stack Overflow
stackoverflow.com › questions › 70464062 › node-js-6-0-0-buffer-to-string-equivalent-in-python3
node.js 6.0.0 buffer to string equivalent in python3
Just don't try to decode at all. Decoding turns bytestrings into text strings, and a hash isn't a text string. kdf_v = bytes.fromhex('E6F8C08930597B47472620568D207A23E4FCEF4B3F0AA3DC26FF369C622C6E1D') gives you a 32-byte bytes object, which is functionally equivalent to a Node.js Buffer.
🌐
Stack Overflow
stackoverflow.com › questions › 71264074 › python-equivalent-of-node-js-buffer-fromstring-base64
Python equivalent of Node.js Buffer.from('string', 'base64') - Stack Overflow
I'm not sure that base64.b64encode() (or also base64.b64decode(), codecs.encode(), codecs.decode()) in Python is right equivalent of Buffer.from('string', 'base64') in Node.js ... The thing was that authenticationToken should be in base64 string but JS successfully eaten plain string instead of base64 encoded one. So bytearray(base64.b64decode('base64_string')) in python is full equivalent of Buffer.from('base64_string', 'base64') ... Glad to see that you solved it by yourself.
🌐
Futurestud.io
futurestud.io › tutorials › node-js-convert-a-string-to-buffer
Node.js — Convert a String to Buffer - Future Studio
June 22, 2023 - In Node.js you can typically use the static Buffer.from() method to create a buffer from a given input value: const buffer = Buffer.from('your string value', 'utf8')
Find elsewhere
🌐
Adeva
adevait.com › nodejs › convert-node-js-buffer-to-string
How to Convert Node.js Buffer to String | Toptal®
May 26, 2026 - You’ll usually want the default UTF-8 encoding, but it’s possible to indicate a different encoding if needed. To convert from a string to a Buffer object, use the static Buffer.from() method - again optionally passing the encoding.
🌐
Stack Overflow
stackoverflow.com › questions › 47467343 › nodejs-inputstream-buffer-convert-to-string-using-python › 47468116
node.js - Nodejs InputStream Buffer convert to string using python - Stack Overflow
i have one application nodejs which request send to python using python-shell npm package. and python script read data and parse string. nodejs file : teststr.js let buf = `
🌐
Stack Overflow
stackoverflow.com › questions › 61145527 › buffer-to-string-difference-in-nodejs-vs-python
node.js - Buffer to string difference in NodeJs Vs Python - Stack Overflow
April 11, 2020 - 1) Python print(in_buffer) b'\x00\x00\x00>\x00\x03\x00\x00user\x00postgres\x00database\x00postgres\x00extra_float_digits\x002\x00\x00' ... Is there a way to print same output in node (looks like it has something to do with null termination) ... You just don't see the low bytes in Node because you are printing it as a string. Just don't convert it with .toString(). Other than that, JS is going to print the actual characters and you'll lose most of it.
🌐
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.
🌐
Node.js
nodejs.org › api › buffer.html
Buffer | Node.js v26.11.1 Documentation
Unlike 'utf8', each character in the string will be encoded using either 2 or 4 bytes. Node.js only supports the little-endian variant of UTF-16. 'latin1': Latin-1 stands for ISO-8859-1. This character encoding only supports the Unicode characters from U+0000 to U+00FF. Each character is encoded using a single byte. Characters that do not fit into that range are truncated and will be mapped to characters in that range. Converting a Buffer into a string using one of the above is referred to as decoding, and converting a string into a Buffer is referred to as encoding.
🌐
Reddit
reddit.com › r/node › how to convert buffer data to string?
How to convert buffer data to string? : r/node
December 29, 2020 - Are you loading a Word document into a Buffer and are trying to get the text from it? That's not that easy. A Buffer is just a way to hold arbitrary data.
🌐
Mastering JS
masteringjs.io › tutorials › node › buffer-to-string
Using the Buffer `toString()` Function in Node.js - Mastering JS
August 21, 2020 - Node.js buffers are objects that store arbitrary binary data. Buffers have a toString() method that you can use to convert the buffer to a string. 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 converted to a string with utf8 encoding and displayed. Node.js provides robust support for buffers and their conversion to strings.