I have this Express middleware to deliver thumbnails (.jpeg) on demand:
app.get('/thumb/:index', function(req, res){
var index = req.params.index
if (!index) return res.status(404).send()
var jpeg = PATH.join('./thumbs/', index, '.jpg')
res.status(200).sendFile(jpeg)
})
This answer shows how to do it when using .static but I'm not sure how to use it on a app.get middleware.
The goal is to cache all jpeg thumbnails on memory to speed up response and avoid physical disk acccess all the time.