no-new-buffer

March 27, 2026 ยท View on GitHub

๐Ÿ“ Enforce the use of Buffer.from() and Buffer.alloc() instead of the deprecated new Buffer().

๐Ÿ’ผ This rule is enabled in the following configs: โœ… recommended, โ˜‘๏ธ unopinionated.

๐Ÿ”ง๐Ÿ’ก This rule is automatically fixable by the --fix CLI option and manually fixable by editor suggestions.

Enforces the use of Buffer.from and Buffer.alloc() instead of new Buffer(), which has been deprecated since Node.js 4.

Examples

// โŒ
const buffer = new Buffer('7468697320697320612074c3a97374', 'hex');

// โœ…
const buffer = Buffer.from('7468697320697320612074c3a97374', 'hex');
// โŒ
const buffer = new Buffer([0x62, 0x75, 0x66, 0x66, 0x65, 0x72]);

// โœ…
const buffer = Buffer.from([0x62, 0x75, 0x66, 0x66, 0x65, 0x72])
// โŒ
const buffer = new Buffer(10);

// โœ…
const buffer = Buffer.alloc(10);