Created
September 14, 2011 06:58
-
-
Save nobuh/1216007 to your computer and use it in GitHub Desktop.
readdir - node.js readdir sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fs = require('fs'); | |
fs.readdir( process.argv[2], function (err, files) { | |
if (!err) | |
console.log(files); | |
else | |
throw err; | |
}); | |
console.log("Fired callback."); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
var fs = require('fs');
fs.readdir( process.argv[2], function (err, files) {
if (err) {
throw err;
}
console.log(files);
});
console.log("Fired callback.");
by checking for the error first it keeps the reader from looking up and back down when scanning your code, and by catching the error in the IF first, you don't have to write ELSE