January 2019
Intermediate to advanced
460 pages
10h 33m
English
We can serve our production build of the front end through Express.js. This approach is not great for development purposes but is useful for testing the build process and seeing how our live application will act.
Again, replace the previous routing example with the following:
import path from 'path';const root = path.join(__dirname, '../../');app.use('/', express.static(path.join(root, 'dist/client')));app.use('/uploads', express.static(path.join(root, 'uploads')));app.get('/', (req, res) => { res.sendFile(path.join(root, '/dist/client/index.html'));});
The path module offers many functionalities for working with the directory structures.
We use the global __dirname variable to get our project's root directory. ...
Read now
Unlock full access