Buffer

Buffer.from(string)

Encodes a string into a Buffer. UTF-8 is the default. Other overloads accept arrays, buffers and ArrayBuffers with different copy/sharing semantics.

Formal Syntax & Structure

nodejs syntaxnodejs
Buffer.from(string[, encoding])

Parameters & Attributes

NameTypeDescription
stringstringText to encode.
encodingstringSource encoding, default utf8.

Return Value

Buffer

New Buffer for this string overload.

Working Example

Example Snippetnodejs
import { Buffer } from "node:buffer";console.log(Buffer.from("café", "utf8").toString("hex"));
Node.js Reference