Kinda Code
Home/Node/Node.js: The Maximum Size Allowed for Strings/Buffers

Node.js: The Maximum Size Allowed for Strings/Buffers

Last updated: November 29, 2021

Buffers and strings in Node.js are limited in size. The actual maximum size of a buffer or a string changes across platforms and versions of Node.js. You can check yours as follows:

const buffer = require('buffer');

// Get the results in bytes
console.log(
  "The maximum size allowed for a buffer:",
  buffer.constants.MAX_LENGTH,
  "bytes"
);
console.log(
  "The maximum size allowed for a string: ",
  buffer.constants.MAX_STRING_LENGTH,
  "bytes"
);

// In case you want to get the results in MB
console.log(
  "The maximum size allowed for a buffer:",
  buffer.constants.MAX_LENGTH / (1024 * 1024),
  "MB"
);

console.log(
  "The maximum size allowed for a string: ",
  buffer.constants.MAX_STRING_LENGTH / (1024 * 1024),
  "MB"
);

Here’s my output:

The maximum size allowed for a buffer: 4294967296 bytes
The maximum size allowed for a string:  536870888 bytes
The maximum size allowed for a buffer: 4096 MB
The maximum size allowed for a string:  511.9999771118164 MB

Further reading:

You can also check out our Node.js category page for the latest tutorials and examples.