3

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();
});
2

1 Answer 1

4

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'))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.