Try executing the following code:
directoryOps.js
(function(directoryOps) {
var fs = require('fs');
var path = './Logs';
function filesData(items) {
var data = JSON.stringify(items)
console.log('data from module',data);
return data;
}
directoryOps.readDirectory = function() {
fs.readdir(path, function(err,items) {
return filesData(items);
});
};
})(module.exports);
App.js
var directoryOps = require('./directoryOps');
var obj = directoryOps.readDirectory();
Sorry for the changes I made in the file name.
**Note: Also the way you are currently creating "main.js", it would add variables like "fs, path, filesData, readDirectory" to the global scope and hence polluting it . So its better to execute the function as a part of IIFE (anonymous function). This would not add variable to the global scope, keeping your scope clean.
Hope it helps...