Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does express serve static files from hidden (dot) folder

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

like image 256
Rouz Avatar asked Jun 30 '16 13:06

Rouz


People also ask

Does Express allow you to serve static files?

Express offers a built-in middleware to serve your static files and modularizes content within a client-side directory in one line of code.

What does Express static () return?

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.

How static files are served in node?

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.

What is a static file Express?

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.


1 Answers

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

like image 72
Keith Avatar answered Sep 17 '22 21:09

Keith