I am using esausilva/example-create-react-app-express to create a base for my MERN project
Inside the ~/server.js file it was written
if (process.env.NODE_ENV === 'production') {
// Serve any static files
app.use(express.static(path.join(__dirname, 'client/build')));
// Handle React routing, return all requests to React app
app.get('*', function(req, res) {
res.sendFile(path.join(__dirname, 'client/build', 'index.html'));
});
}
To my understanding this mean if the express server is running in production mode then it will look into the client/build folder to serve the static file(i.e front-end code) and for any route request the server will send client/build/index.html file.
Inside the package.json i have the following npm run command
"scripts": {
"client": "cd client && yarn start",
"server": "nodemon server.js",
"dev": "concurrently --kill-others-on-fail \"yarn server\" \"yarn client\"",
"dev:server": "cd client && yarn build && cd .. && yarn start",
"start": "node server.js",
"heroku-postbuild": "cd client && npm install && npm install --only=dev --no-shrinkwrap && npm run build"
},
my confusion is when i run yarn dev it run the server and react app concurrently(everything is perfect) but inside the client folder i don't see any physical build folder,why this is that happening, how express server understand which file to serve if it don't create the build folder first.