From 8b6638ef834791896e17edd9285965a7fe386a84 Mon Sep 17 00:00:00 2001 From: Jo Franchetti Date: Wed, 7 May 2025 17:46:09 +0100 Subject: [PATCH] update info on buffer --- runtime/fundamentals/node.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/runtime/fundamentals/node.md b/runtime/fundamentals/node.md index 1e5cf56b4..6e6bb503b 100644 --- a/runtime/fundamentals/node.md +++ b/runtime/fundamentals/node.md @@ -551,6 +551,18 @@ import { Buffer } from "node:buffer"; const buf = new Buffer(5, "0"); ``` +For TypeScript users needing Node.js-specific types like `BufferEncoding`, these +are available through the `NodeJS` namespace when using `@types/node`: + +```ts title="buffer-types.ts" +/// + +// Now you can use NodeJS namespace types +function writeToBuffer(data: string, encoding: NodeJS.BufferEncoding): Buffer { + return Buffer.from(data, encoding); +} +``` + Prefer using [`Uint8Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array) or other