Node.js string_decoder: decode buffers into strings safely
Answer: The node:string_decoder module decodes Buffer objects into strings while preserving multi-byte UTF-8 and UTF-16 characters. new StringDecoder(encoding) creates a decoder. After end() runs, the same decoder can be reused.
Examples
import { StringDecoder } from 'node:string_decoder';
const decoder = new StringDecoder('utf8');
Notes
end() returns any remaining input stored in the internal buffer as a string. The module is stable.
Reference list
string_decoderdecodes Buffer objects into strings.StringDecoderis the class you construct with an encoding.
See also
Claims
- id: C1 claim: The module decodes Buffer objects into strings. source: S1 evidence: "The node:string_decoder module provides an API for decoding Buffer objects"
- id: C2 claim: The docs show basic use of the StringDecoder class. source: S1 evidence: "The following example shows the basic use of the StringDecoder class."
- id: C3 claim: After end() the decoder can be reused for new input. source: S2 evidence: "After
end()is called, thestringDecoderobject can be reused for new input."
Sources
- [S1] String decoder. Node.js docs. https://nodejs.org/api/string_decoder.html . License: MIT. Accessed 2026-11-18.
- [S2] string_decoder.md. Node.js. https://raw.githubusercontent.com/nodejs/node/main/doc/api/string_decoder.md . License: MIT. Accessed 2026-11-18.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Node.js docs, String decoder; Node.js, string_decoder.md. MIT (https://raw.githubusercontent.com/nodejs/node/main/LICENSE). Copyright Node.js contributors. Text was condensed and changed from the originals.
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Node.js docs, String decoder; Node.js, string_decoder.md. MIT (https://raw.githubusercontent.com/nodejs/node/main/LICENSE). Copyright Node.js contributors.
Cite this
iinventedlight. 2026. "Node.js string_decoder: decode buffers into strings safely." iinventedlight Library, iil:note:h3knwmtx, version of 2026-11-18. https://iinventedlight.com/library/notes/node-string-decoder/. License: CC-BY-4.0.
@misc{iil_note_h3knwmtx,
author = {{iinventedlight}},
title = {{Node.js string\_decoder: decode buffers into strings safely}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-18},
url = {https://iinventedlight.com/library/notes/node-string-decoder/},
note = {Permanent ID iil:note:h3knwmtx. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).
For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/node-string-decoder.md.