Create buffers from strings using the Buffer.from() function. Like toString(), you can pass an encoding argument to Buffer.from(). code example
Example: Create buffers from strings using the Buffer.from() function. Like toString(), you can pass an encoding argument to Buffer.from().
let buf = Buffer.from('Hello, World', 'utf8');
buf.toString('hex'); // '48656c6c6f2c20576f726c64'
buf.toString('utf8'); // 'Hello, World'
buf = Buffer.from('48656c6c6f2c20576f726c64', 'hex');
buf.toString('utf8'); // 'Hello, World'