You should loop through the string and do this on each character:

 let result = ""
 
 for (let i = 0; i < myString.length; i++) {
      result += myString[i].charCodeAt(0).toString(2) + " ";
  }

Answer from nedoder on Stack Overflow
🌐
GitHub
github.com › nodejs › help › issues › 2063
Turn string into binary data · Issue #2063 · nodejs/help
July 19, 2019 - but when this result is passed as a parameter to Redis to be saved, it is saving it as a json string. I have tried using .toString('binary') and have not gotten any traction by changing up the encoding. Before I dig into the source code of the redis library to see if it does any conversions, is it possible that I am using Buffer improperly?
Author: nodejs
🌐
Java2s
java2s.com › example › nodejs › number › string-to-binary-and-unbinary.html
String to binary and unbinary - Node.js Number
Binary · String to binary and unbinary · String.prototype.bin = function() { if (this.substr(0, 2) == "0x") { bytes = []/*ww w . j ava 2 s .co m*/ var i = 2; // Check if it's odd - pad with a zero if so.
🌐
Stack Overflow
mariokandut.com › how to handle binary data in node.js?
How to handle binary data in Node.js? - Mario Kandut
February 28, 2022 - In order to convert a string to a binary representation, an encoding has to be defined. The default encoding for Buffer.from is UTF8. The UTF8 encoding may have up to four bytes per character, so string length will not always match the converted buffer size.
🌐
npm
npmjs.com › package › binstring
binstring - npm
April 13, 2014 - The input format is duck-typed if it's an Array (bytes) or Buffer (buffer) or Number object. If it's a string, it's interpreted as binary unless it's prefixed by 0x (then it's hex).
      » npm install binstring
    
Published: Apr 13, 2014
Version: 0.2.1
Find elsewhere
🌐
GitHub
github.com › nodejs › node › issues › 12908
Can't convert Buffer into String correctly with binary encoding · Issue #12908 · nodejs/node
May 8, 2017 - Hello, I was working with binary files and Buffer, and encountered this problem. Code: b = Buffer.from([0xca, 0xc5, 0x0e]) console.log(b.toString('binary')) console.log(b) I would expect as output something like: ÊÅ^N which is exactly th...
Author: nodejs
🌐
npm
npmjs.com › package › binary-string
binary-string - npm
August 30, 2012 - Latest version: 1.0.0, last published: 14 years ago. Start using binary-string in your project by running `npm i binary-string`. There are 1 other projects in the npm registry using binary-string.
      » npm install binary-string
    
Published: Aug 30, 2012
Version: 1.0.0
🌐
Stack Overflow
stackoverflow.com › questions › 53776805 › nodejs-download-file-and-convert-to-binary-string
NodeJS: Download File and convert to binary string
December 14, 2018 - You can use an ArrayBuffer to hold binary data, then convert the ArrayBuffer to a Hex string.
🌐
GitHub
github.com › s-faisal › str2bin
GitHub - s-faisal/str2bin: JavaScript library to convert any String to Binary Code and vice-versa · GitHub
const str2bin = require("str2bin") str2bin.strToBin(string) str2bin.binToStr(binaryCode, delimiter) str2bin.strToBin("hello") ## returns "01101000 01100101 01101100 01101100 01101111" str2bin.binToStr("01101000 01100101 01101100 01101100 01101111") ## returns "hello" str2bin.binToStr("01101000-01100101-01101100-01101100-01101111", "-") ## returns "hello" ... ## str2bin -s "string_that_needs_to_be_converted" str2bin -s "hello" ## returns "01101000 01100101 01101100 01101100 01101111" ## str2bin -b "binary_string_that_needs_to_be_converted" str2bin -b "01101000 01100101 01101100 01101100 01101111" ## returns 'hello' ## str2bin -b "binary_string_that_needs_to_be_converted" -d "delimiter" str2bin -b "01101000-01100101-01101100-01101100-01101111" -d "-" ## returns "hello"
Author: s-faisal
🌐
TutorialsPoint
tutorialspoint.com › article › string-to-binary-in-javascript
String to binary in JavaScript
March 15, 2026 - const convertToBinary = (text) => { let binary = []; for (const char of text) { binary.push(char.charCodeAt(0).toString(2)); } return binary.join(' '); }; console.log(convertToBinary('ABC')); console.log(convertToBinary('123')); ... const ...
🌐
DEV Community
dev.to › thebridge2 › intro-to-binary-with-nodejs-buffer-examples-c0k
Intro to Binary with NodeJS Buffer examples - DEV Community
March 28, 2023 - Because of this, for large data it is more efficient to best to send data using binary or hex format. This why NodeJS streams support the Buffer format (in addition to strings and objects).
🌐
npm
npmjs.com › search
binary-to-text - npm search
Conversion of JavaScript primitives to and from Buffer with binary order matching natural primitive order