Buffer

Buffer.writeUInt16LE()

Stores an unsigned two-byte integer with its least significant byte first. Tested on Node.js 22.16.0. Validate integer bounds and available space before encoding external values.

Formal Syntax & Structure

nodejs syntaxnodejs
buf.writeUInt16LE(value[, offset])

Parameters & Attributes

NameTypeDescription
valueintegerInteger from 0 to 65535.
offsetintegerFirst byte position, default 0.

Return Value

number

Offset immediately after the written bytes.

Working Example

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