I'm trying to make a simple NodeJS module with the following pattern:module.exports = function () {}
.
My problem is that when I write exports.myFunc = myFunc;
it works well, but when I write module.exports = myFunc;
it doesn't work.
Here's some of my code snippets:
function.js:
var fs = require('fs');
var path = require('path');
var i = 0;
function getFilesByExtArgs (dir, ext){
fs.readdir(dir, function (err, data){
while (i <= data.length){
if (path.extname(data[i]) == ('.' + ext))
console.log(data[i]);
i++;
}
});
}
exports.getFilesByExtArgs = getFilesByExtArgs;
module.js:
var myModule = require('./listFilesByExtArgs');
myModule.getFilesByExtArgs(process.argv[2], process.argv[3]);
How can I make my code work with the pattern needed ?