I'm trying to make a proper asynchronous function which contains a callback but apparently my way of doing this doesn't work.
Here's my code:
var fs = require('fs');
var path = require('path');
var tmp = 0;
var i = 0;
function getFilesByExtArgs(dir, ext, function(err)){
if (err){
console.log("Error: " + err.code + " (" + err.message + ")");
return;
}
else{
fs.readdir(dir, function (err, data){
while (i <= data.length){
if (path.extname(data[i]) == ('.' + ext))
console.log(data[i]);
i++;
}
});
}
}
module.exports = getFilesByExtArgs;
When I try to launch that, I get the following error:
function getFilesByExtArgs(dir, ext, function(err)){
^^^^^^^^
SyntaxError: Unexpected token function
How can I make it "the node way" ?