Node js module How to get list of exported functions

Given the node js module / package, is there any way to retrieve all the functions exported by this module?

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

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

      

Then I would like to have the following list as export: tokenizer, parse, slice, curry

+3


source to share


2 answers


You can require a file and just map object keys, which will return an array of exported object names.



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

console.log(Object.keys(myExports));

      

+7


source


Here's a quick and easy way:



console.dir(Object.keys(require('foo')));

      

+4


source







All Articles