MatUtter MatUtter - 5 months ago 11
Node.js Question

How to make NodeJS addon show property info like a regular object

I have an addon created with several prototypes but when I try to

console.log( myinstace )
the're no properties listed.
{}
is the result. The desired outcome would be something like below. How do I make this happen?

addon.cc

Local<FunctionTemplate> self = FunctionTemplate::New(New);
self->PrototypeTemplate()->Set(
String::NewSymbol("Method")
, FunctionTemplate::New(method)
);


app.js

console.log( myinstance ); // desired { Method : [Function: Method ] }

Answer

In general using inspect from the util package will give the deepest examination of an objects properties and prototypes.

const util = require('util')
var mod = require(...)
console.log(util.inspect(mod))
Comments