Reputation: 315
I have a simple use case for an application; a user can upload images to server where they are stored in a directory, and a user can view all images uploaded and stored in this directory.
The functionality for the first criteria is working, and the application persists uploaded images to the image directory.
The next step is to return all images. For the front end, i will use some kind of tile gallery to render images to the user. However, my question is related to how best to return "all images" to the end user, through express js.
Essentially, I am hoping to do a directory dump, but am confused as to an elegant (read: any!) solution on how to do this. Any advice or suggestion most appreciated.
Edit: to clarify, the route should return all images when hit. As future implementations will filter images based on certain criteria.
example:
// return the view page for register
app.get('/gallery',function(req,res){
// return images here
res.send();
});
Upvotes: 3
Views: 2923
Reputation: 366
If I understood you correctly, all you need to do is to statically serve a folder. For that, you can use
app.use('/images', express.static('path/to/images'))
Upvotes: 4