Categories
JavaScript Answers

How to get the string length in bytes in Node?

Spread the love

To get the string length in bytes in Node, we call the Buffer.byteLength method.

For instance, we write

const getBytes = (string) => {
  return Buffer.byteLength(string, "utf8");
};

to call Buffer.byteLength with the string to get the string‘s length in byte.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *