Skip to content

Serve Static Content

ItzNotABug edited this page May 3, 2024 · 1 revision

You can serve static content meant for public access directly without any routing or a middleware. This behaviour is similar toexpress.static() middleware.

  1. First off, define a directory that contains the static content like this -

    appExpress.static('public');
  2. Now you can directly access the contents by visiting the file paths.

  3. You can also exclude certain files, in case of sensitive content, or you use a middleware to handle a content -

    express.static('public', ['.env', /config/g]);

Clone this wiki locally