Skip to content

Instantly share code, notes, and snippets.

@pingjiang
Created October 13, 2014 14:54
Show Gist options
  • Save pingjiang/9a9b39b267a3820c91f6 to your computer and use it in GitHub Desktop.
Save pingjiang/9a9b39b267a3820c91f6 to your computer and use it in GitHub Desktop.
NodeJS Loop trap, callback is called nextTick.
var fs = require('fs');
var files = ['a.txt', 'b.txt', 'c.txt'];
for (var i = 0; i < files.length; i++) {
fs.readFile(files[i], 'utf-8', function(err, contents) {
console.log(files[i] + ': ' + contents);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment