Ron Melkhior Ron Melkhior - 1 year ago 60
Node.js Question

Requiring a folder and using exports.{function}

Currently I have this setup:

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


// folder/index.js

// folder/test.js
exports.thing = function() {

return true;

But when I try in
to call
I get:

example.thing is not a function

Is there any way to make it work? Cheers.

Answer Source

Directory requiring is not supported by node. It requires index.js if it presented in the directory.

To export thing in index.js do the following:

// index.js
exports.thing = require('./test.js').thing;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download