Advertisement
Guest User

Untitled

a guest
Oct 7th, 2015
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.45 KB | None | 0 0
  1. // List all files in a directory and reverse the list (newest on top)
  2.  
  3. async.waterfall([
  4. function(cb) {
  5. var filenames = []
  6. fs.readdir('/dir', function(err, files) {
  7. if (err) return;
  8. for(var i = 0; i < files.length; i++){
  9. filenames.push(files[i])
  10. if(i === files.length - 1){
  11. cb(null, filenames.reverse());
  12. }
  13. }
  14. });
  15. },
  16. function(filenames) {
  17. return res.status(200).json(filenames)
  18. }
  19. ]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement