0

I want to show all the files in the uploads folder as a list of files when serving via express.

Using app.use(express.static("public")); only serves individual files.

I cannot directly see all files in that folder like if I go to localhost:3000/public

Vignesh S
  • 332
  • 1
  • 2
  • 14
  • what you're after is like FTP-Listing, and that can be accomplished [with this answer](https://stackoverflow.com/a/27391258/28004) – balexandre Apr 29 '21 at 19:26
  • 1
    @balexandre Thanks a lot that worked. I couldn't google it the right way for some reason all the answers I got was just express.static solution – Vignesh S Apr 29 '21 at 19:35

1 Answers1

1

Found the solution with the help of above comments thanks to @Balexandre.

var serveIndex = require('serve-index');

app.use(express.static(path.resolve(__dirname, "public")));
app.use("/public", serveIndex(path.resolve(__dirname, "public")));
Vignesh S
  • 332
  • 1
  • 2
  • 14