While I'm aware that code with callbacks tends to be complex, I'm wondering if there are any patterns or something to improve my situation.
All I do here is check if a file exists and then print its name if it's not a directory:
var fs = require('fs'),
filename = process.args[2];
fs.exists(filename, function(exists) {
if (exists) {
fs.stat(filename, function(err, stats) {
if (stats.isDirectory()) {
console.log(filename + ": is a directory");
} else {
// do something with file
console.log(filename);
}
});
} else {
console.log(filename + ": no such file");
}
});