Buffer

buffer.transcode()

Converts between supported character encodings. Unrepresentable characters may be substituted, so this is not guaranteed lossless. Tested on Node.js 22.16.0. Example output (one line per entry): ["e9"].

Formal Syntax & Structure

nodejs syntaxnodejs
transcode(source, fromEnc, toEnc)

Parameters & Attributes

NameTypeDescription
sourceBuffer | Uint8ArraySource bytes.
fromEncstringSource encoding.
toEncstringDestination encoding.

Return Value

Buffer

Converted bytes.

Working Example

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