user1726366
user1726366

Reputation: 2416

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');
undefined
> 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

Upvotes: 1

Views: 241

Answers (1)

etchesketch
etchesketch

Reputation: 873

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}'

Upvotes: 2

Related Questions