Skip to content

Instantly share code, notes, and snippets.

@dylanbathurst
Forked from alexcoleman/gist:5778024
Last active December 18, 2015 11:49
Show Gist options
  • Save dylanbathurst/5778179 to your computer and use it in GitHub Desktop.
Save dylanbathurst/5778179 to your computer and use it in GitHub Desktop.
// Photos
app.get('/photos', function (req, res, next) {
var view = {};
fs.readdir('./public/img/slideshow', function(err, files) {
var re = /\.(gif|jpg|jpeg|tiff|png)$/i;
var list = files.filter(function (file) {
return re.test(file);
});
var randomPhotoIndex = Math.floor(Math.random() * thePhotos().length);
view.photo = list[randomPhotoIndex];
res.render('photos', view);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment