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
The module.js is used to export any literal, function or object as a module. It is used to include JavaScript file into node. js applications. The module is similar to variable that is used to represent the current module and exports is an object that is exposed as a module.
Module exports are the instruction that tells Node. js which bits of code (functions, objects, strings, etc.) to “export” from a given file so other files are allowed to access the exported code.
To export multiple functions in JavaScript, use the export statement and export the functions as an object. Alternatively, you can use the export statement in front of the function definitions. This exports the function in question automatically and you do not need to use the export statement separately.
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));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With