I'm working with nodeJS and expressJS. I Have 2 functions, main functions:
download(imgUrl, imgMD5, function(fileLength, fileSize) {
console.log(fileLength);
var qb = data.Img.query();
qb.where('img_md5', '=', imgMD5).update({
img_downloaded: 1
}).then(function() {});
});
and external function
module.exports = function() {
return function(uri, filename) {
request(uri, function(err, res, callback) {
fileLength = res.headers['content-length'];
var mkdirs = function(fold, callback) {
var pf = path.dirname(fold);
fs.exists(pf, function(exists) {
var create = function() {
fs.mkdir(fold, callback);
};
if (exists) {
create();
} else
mkdirs(pf, create);
})
};
var folder = ('./downloaded/' + yy + '/' + mm + '/' + dd + '/' + ho + '/');
mkdirs(folder, function() {
var r = request(uri).pipe(fs.createWriteStream(folder + filename));
r.on('close');
});
callback(fileLength);
});
};
};
but it's fired an error when running:
TypeError: string is not a function
I don't know if I'm uses the callback right or not?
thank you