Aditya M P
Aditya M P

Reputation: 5367

How to discover Object APIs in the Node.js console?

The Canary Developer Tools offer great features like console.table and console.dir which give details about the various functions and properties available on an object.

I'd like to know if this is somehow possible in the Node.js REPL. I've tried a few combinations that work great in the browser developer tools:

> console.dir(Promise)
[Function: Promise]
undefined
> console.log(Promise)
[Function: Promise]
undefined
> Promise
[Function: Promise]
> console.table(Promise)
TypeError: console.table is not a function
    at repl:1:9
    at REPLServer.defaultEval (repl.js:248:27)
    at bound (domain.js:280:14)
    at REPLServer.runBound [as eval] (domain.js:293:12)
    at REPLServer.<anonymous> (repl.js:412:12)
    at emitOne (events.js:82:20)
    at REPLServer.emit (events.js:169:7)
    at REPLServer.Interface._onLine (readline.js:210:10)
    at REPLServer.Interface._line (readline.js:549:8)
    at REPLServer.Interface._ttyWrite (readline.js:826:14)

How do I get access and documentation about these functions and more inside Node without having to open MDN or Node.js docs?

Upvotes: 0

Views: 74

Answers (1)

apsillers
apsillers

Reputation: 115990

All of Promise's properties are non-enumerable and are therefore hidden by default from Node's logging. You can use the showHidden option of Node's console.dir to show them:

showHidden - if true then the object's non-enumerable and symbol properties will be shown too. Defaults to false.

When you run console.dir(Promise, { showHidden: true }) you'll see all the properties of the object.

Upvotes: 2

Related Questions