Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // List all files in a directory and reverse the list (newest on top)
- async.waterfall([
- function(cb) {
- var filenames = []
- fs.readdir('/dir', function(err, files) {
- if (err) return;
- for(var i = 0; i < files.length; i++){
- filenames.push(files[i])
- if(i === files.length - 1){
- cb(null, filenames.reverse());
- }
- }
- });
- },
- function(filenames) {
- return res.status(200).json(filenames)
- }
- ]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement