My app is serving a static folder like this
app.use('/static', serveStatic(__dirname + '/view/my/static/folder'));
How to configure server to serve a hidden folder? So if i have
/view/my/static/folder/.hidden/some-text.txt
I would like to see this on
localhost:8080/static/.hidden/some-text.txt
Express offers a built-in middleware to serve your static files and modularizes content within a client-side directory in one line of code.
use() function executes middleware in order. The express. static() middleware returns an HTTP 404 if it can't find a file, so that means you should typically call app.
Serve Static Resources using Node-static Module The node-static module is an HTTP static-file server module with built-in caching. First of all, install node-static module using NPM as below. After installing node-static module, you can create static file server in Node. js which serves static files only.
Static files are files that clients download as they are from the server. Create a new directory, public. Express, by default does not allow you to serve static files. You need to enable it using the following built-in middleware. app.
I found this question from googling after I couldn't serve hidden files. I discovered that express doesn't serve them by default.
You can serve them with the dotfiles
option:
app.use(express.static( __dirname+'/static', {dotfiles:'allow'} ));
source
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With