30

Given a node js module/package, is there some way I can extract out all functions exported by that module ?

For example - if the module has a js file with following code:

exports.tokenizer = tokenizer;
exports.parse = parse;
exports.slice = slice;
exports.curry = curry;

Then I would like to have a following listed as exports: tokenizer, parse, slice, curry

Vibha Singhal
  • 420
  • 1
  • 4
  • 5

2 Answers2

51

You can require the file and just map through the object keys, which would return an array of the names of the exported objects.

var myExports = require('./exported-file.js');

console.log(Object.keys(myExports));
Ben Fortune
  • 31,623
  • 10
  • 79
  • 80
12

Here's a quick and easy way:

console.dir(Object.keys(require('foo')));
mscdex
  • 104,356
  • 15
  • 192
  • 153