How do I run both the back end and front end of my app on glitch?


I usually run my apps’s code in visual basic: with npm run start watch(nodemon) for back end, and npm start for my create-react-app front end side on another console.

How can I run it in a similar way on glitch?. This is the code I want to start both FE and BE there:!/mern-todo

In glitch you only have access to one server per app, unlike locally where you can startup multiple servers simultaneously, therefore you have to do a build for your CRA client (yarn build) and upload to glitch and then serve that static build folder from your glitch app.
**of course, this means every time you update client you have to do another build.

Alright, I ran yarn build and It created a production build folder. The console says that I can deploy it and serve it with a static server through npm install -g serve or serve -s build.

So i just have to upload this build folder inside the client folder or root of my glitch project and run npm install -g serve in console?.

No, just upload your build folder to your glitch app and use it in your index.js server file, depending on what your build folder is named , you could do something like

app.use(express.static(path.join(__dirname, '../client/build')));

and a wild card route after all other routes to catch your index.html file

app.get('*', (req, res) => {
  res.sendFile(path.resolve(__dirname, '../client/build', 'index.html'));

you have to require the path module if you haven’t already