How to check whether a data or an object is a Buffer in Node.js?

Published September 22, 2020

To check whether some data or an object is a Buffer, you can use the isBuffer() method in the global Buffer class in Node.js.

// a buffer
const buff = Buffer.alloc(10);

// check whether buff object is
// an instance of Buffer class
const isItBuffer = Buffer.isBuffer(buff);

console.log(isItBuffer); // true
  • The method returns boolean true if it is an instance of Buffer class and false if not.

Feel free to share if you found this useful 😃.


Share on: Facebook Twitter