0

I'm trying to serve static files using nodejs and express js. In the code I have:

server.use('/public', express.static(__dirname + '/public'));

But when I try to enter locahost:myPort/public i get

Cannot GET /public/

I have some two other mappings: "/search.html" and "/download.html" and those pages works fine. What I would like to get is the files list, which are in the public folder.

Is it possible to get such results?

1 Answer 1

1

What you are looking for is possible through the use of the serve-index middleware. https://github.com/expressjs/serve-index

npm install serve-index

.

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

app.use('/public', serveIndex('/public'));
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.