// If you can use Node.js you can use the from() method const str = "Hey. this is a string!"; const buff = Buffer.from(str, "utf-8"); console.log(buff);