DEV Community

Cover image for How to check whether a data or an object is a Buffer in Node.js?
MELVIN GEORGE
MELVIN GEORGE

Posted on • Originally published at melvingeorge.me

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

Originally posted here!

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
Enter fullscreen mode Exit fullscreen mode
  • 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 😃.


Top comments (0)