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
| Name | Type | Description |
|---|---|---|
| encoding | string | Output encoding. |
| start | integer | First byte offset, default 0. |
| end | integer | Exclusive 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));