import { Buffer } from 'buffer'; const message: string = "Hello, World!"; const buffer: Buffer = Buffer.alloc(message.length); buffer.write(message, 0, 'utf-8'); console.log(buffer.toString());
import { Buffer } from 'buffer'; const message: string = "Hello, World!"; const encoded: string = Buffer.from(message, 'utf-8').toString('base64'); console.log(encoded); const decoded: string = Buffer.from(encoded, 'base64').toString('utf-8'); console.log(decoded);In this example, we are encoding a message in UTF-8 format to Base64 format using the `from()` method with the `utf-8` and `base64` encoding options. We then decode the encoded message back to its original format using the `from()` method with `base64` and `utf-8` encoding options. Package Library: `buffer` (built-in Node.js module)