- Full-Stack React Projects
- Shama Hoque
- 59字
- 2021-06-25 21:45:13
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')))