So, I'm going through the Node.js learnyounode tutorial (which is pretty fun), but I'm no stranger to javascript. One of the requests is to have the user write a program that accepts a directory and a file extension as arguments, and then proceeds to ls the files which match the given extension.
In checking my arguments in various places where data is passed through functions, I cannot get Node.js to allow me to pass additional arguments to a callback function for a built-in function.
For example, I can run the following snippet, pass an err, path, and extension, and would like to see the all the passed arguments, but I only see err and data in the arguments object while the "ext" variable is ignored.
var fs = require("fs"), path = require("path")
var dir = process.argv[2], ext = process.argv[3];
fs.readdir(dir, function (err, data, ext) {
console.log(arguments);
});
The reason for wanting this functionality is to avoid breaking the function scope to retrieve the value of ext.
I can do this type of thing with custom functions all day, but the built-in functions are a little less forgiving.
Thanks, Bob