I have a few files, requiring each other recursively.
routes.js requires api.js.api.js requires upload.js, pixels.js, etc.
From upload.js or pixels.js I want to use fn's in api.js.
Currently I'm requring like so, but it doesn't work:
// routes.js
var api = require('./api');
api.upload.image(args); // a fn run from routes.js
.
// api.js
module.exports = {
upload : require('./upload');
}
.
// pixels.js
module.exports = {
get : function (args) {
console.log(args);
}
}
.
// upload.js
var api = module.parent.exports; // <= tricky part
module.exports = {
image : function (args) {
api.pixels.get(args); // <= api is undefined
}
}
The module.parent.exports are empty in the sub-modules, and I can't figure out how to require them properly.
How should I require to get this functionality?
Aucun commentaire:
Enregistrer un commentaire