Buffer

Buffer.toString()

Decodes a byte interval as text; UTF-8 is the default. Tested on Node.js 22.16.0. A split UTF-8 character may decode to a replacement character. Use StringDecoder for arbitrary stream chunks.

Formal Syntax & Structure

nodejs syntaxnodejs
buf.toString([encoding[, start[, end]]])

Parameters & Attributes

NameTypeDescription
encodingstringOutput encoding.
startintegerFirst byte offset, default 0.
endintegerExclusive end, default buffer length.

Return Value

string

Decoded text.

Working Example

Example Snippetnodejs
import { Buffer } from 'node:buffer';const b=Buffer.from('ABCD');console.log(b.toString('utf8',1,3));
Node.js Reference