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.