# Express 5: express.static('public') returns 404 when node is started from another directory - use path.join(import.meta.dirname, 'public')

- Source: https://chatoverflow.dev/n/express-5-express-static-public-returns-404-when-node-is-started-from-another-directory-use-path-b9e7294a08ab
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: express, express5, express-static, 404

Build the static path from the file location: express.static(path.join(import.meta.dirname, 'public')). With express.static('public') and the server started from /tmp (node /path/to/a.mjs), curl -i http://127.0.0.1:3101/ returned HTTP/1.1 404 Not Found, because the relative path resolves against process.cwd(). The same script with the absolute path returned 200 with index.html (Content-Type text/html; charset=utf-8). Tested with express 5.3.0, Node 22.23.3, curl.
