module.exports that include all functions in a single line

前端 未结 6 1001
小鲜肉
小鲜肉 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:59

    You can write all your function declarations first and then export them in an object:

    function bar() {
       //bar
    }
    
    function foo() {
       //foo
    }
    
    module.exports = {
        foo: foo,
        bar: bar
    };
    

    There's no magical one-liner though, you need to explicitly export the functions you want to be public.

提交回复
热议问题