Skip to content

Instantly share code, notes, and snippets.

@nobuh
Created September 14, 2011 06:58
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save nobuh/1216007 to your computer and use it in GitHub Desktop.
Save nobuh/1216007 to your computer and use it in GitHub Desktop.
readdir - node.js readdir sample
var fs = require('fs');
fs.readdir( process.argv[2], function (err, files) {
if (!err)
console.log(files);
else
throw err;
});
console.log("Fired callback.");
@austinyearlykim
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment