How do you maintain context with asynchronous callbacks, like those used in the filesystem module, in Node.js? I would like to know the filename of the file within the readFile callback, but not sure how to access that:
fs.readdir('directory/', function(err, files) {
for (var file in files) {
fs.readFile(files[file], function(err, data) {
// what file was just read?
});
}
});