module.exports that include all functions in a single line

前端 未结 6 1002
小鲜肉
小鲜肉 2021-02-05 10:19

This is a follow-up question to In Node.js, how do I "include" functions from my other files?

I would like to include an external js file that contains common

6条回答
  •  逝去的感伤
    2021-02-05 10:56

    I have done something like the following:

    var Exported = {
       someFunction: function() { },
       anotherFunction: function() { },
    }
    
    module.exports = Exported;
    

    I require it in another file and I can access those functions

    var Export = require('path/to/Exported');
    Export.someFunction();
    

    This is essentially just an object with functions in it, and then you export the object.

提交回复
热议问题