需要一个文件夹并使用导出。{function}

Requiring a folder and using exports.{function}

目前我有这个设置:

// index.js
var example = require('./folder');

和:

// folder/index.js
require('./more');

// folder/test.js
exports.thing = function() {
    console.log('test');

    return true;
}

但是当我尝试在 index.js 中调用 example.thing 时,我得到:

example.thing is not a function

有什么办法让它起作用吗?干杯。

你说的对吗?因为我试过了,而且有效。

你应该这样称呼它 example.thing() 而不是 example.thing

节点不支持需要的目录。如果它出现在目录中,则需要 index.js

要在 index.js 中导出 thing,请执行以下操作:

// index.js
exports.thing = require('./test.js').thing;