Say I have the following module makeDir which checks for the existence of a directory and creates one if it does not exist or simply calls its callback with null if the directory already exists.
Which would be the proper way to export this module?
module.exports = makeDir or module.exports.makeDir = makeDir ?
'use strict';
var fs = require('fs');
var mkdirp = require('mkdirp');
var makeDir = {};
makeDir.handler = function (dstPath, sizesObj, callback) {
var _path = dstPath + sizesObj.name + "/";
fs.lstat(_path, function (err, stats) {
if (err) {
mkdirp(_path, function (err, made) {
if (err) {
console.log("Error creating directory: %s", err);
callback (err, null);
} else {
console.log("Created new directory");
callback(null, made);
}
});
} else {
callback(null);
}
});
};
module.exports = makeDir;