Search code examples
javascriptnode.jsexpressmodel-view-controllerstatic-files

How to make express serve static files from another upper directory?


If I have an nodejs express application with folowing folder structure:

-src - client - public - css - js - ... - views - server - server.js

  • How can I serve the static files in the public folder from the server.js file, since it is located above the index.js root location?
  • How should the:

app.use(express.static();

look like?

----UPDATE---

SOLVED this by using: app.use(express.static(path.join(__dirname, '/../client/public')));


Solution

  • Actually solved my problem by using:

    app.use(express.static(path.join(__dirname, '/../client/public')));