user1726366 user1726366 - 4 years ago 75
Node.js Question

How to get the details of a module function with repl in nodejs?

By using tab in Nodejs REPL I could get the information of a module, e.g. module url like below. But what if I want to know the details of a function in it? e.g. I want to know what parameters the url.parse function need, and the details of them. Can I get this information offline from REPL?

> var url = require('url');
> url.
url.__defineGetter__ url.__defineSetter__ url.__lookupGetter__
url.__lookupSetter__ url.__proto__ url.constructor
url.hasOwnProperty url.isPrototypeOf url.propertyIsEnumerable
url.toLocaleString url.toString url.valueOf

url.URL url.Url url.domainToASCII
url.domainToUnicode url.format url.originFor
url.parse url.resolve url.resolveObject

Answer Source

Try calling url.parse.toString() this will give you the 'source' of the function.

In case of url.parse this technique returns (in node 6.9.2 on Ubuntu) 'function urlParse(url, parseQueryString, slashesDenoteHost) {\n if (url instanceof Url) return url;\n\n var u = new Url();\n u.parse(url, parseQueryString, slashesDenoteHost);\n return u;\n}'

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download