Serving static files with Express

To ensure that the Express server properly handles the requests to static files such as CSS files, images, or the bundled client-side JS, we will configure it to serve static files from the dist folder by adding the following configuration in express.js.

mern-skeleton/server/express.js:

import path from 'path'const CURRENT_WORKING_DIR = process.cwd()app.use('/dist', express.static(path.join(CURRENT_WORKING_DIR, 'dist')))

Get Full-Stack React Projects now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.