How to get class name of an object in Node JS

The question is very simple. If you are an instance of, for example, a buffer you do:

b = new Buffer(0);

      

then you are checking the type:

typeof b;

      

The result is "Object", but I want to know what is Buffer.

If you did it in the node console you get it:

> b = new buffer (1024); > type b
"Object"
> b
<Buffer ...>

So some how the console knows b is a buffer.

+3


source to share


1 answer


In your case:

b = new Buffer(1024);
if (b instanceof Buffer) {
  ...

      



In general, see this answer .

+8


source