Node js module how to get list of exported functions

前端 未结 2 1876
离开以前
离开以前 2021-01-01 17:19

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

相关标签:
2条回答
  • 2021-01-01 17:35

    Here's a quick and easy way:

    console.dir(Object.keys(require('foo')));
    
    0 讨论(0)
  • 2021-01-01 17:40

    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));
    
    0 讨论(0)
提交回复
热议问题