Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to run nodemon to restart server upon changes on front-end?

I'm rather new to this area, so please excuse if this question is completely basic. I've seen some tutorials use nodemon to watch files, and restart servers on Nodejs backend. I've seen others use webpack to watch files such as create react app on frontend. Can you actually use nodemon to watch files and refresh pages on the front end?

like image 457
jen007 Avatar asked Dec 07 '25 20:12

jen007


2 Answers

Yes I believe you can set it up with your package.json scripts! For instance with a node server with a create-react-app within a client folder you could declare a start script along the lines of:

"start": "concurrently \"nodemon server.js\" \"cd client && nodemon start\""

Then when you run npm start this will run nodemon on both the server file and the client folder

Just be aware this assumes your server file is named server.js and your client files are in a folder named client and will require you to have the concurrently dependency installed.

like image 99
Jake Avatar answered Dec 09 '25 09:12

Jake


You could use something like this one if you already have create react app within a client folder. "server": "nodemon server.js", "client": "cd client && yarn start", "dev": "concurrently --kill-others-on-fail \"yarn server\" \"yarn client\""

Concurrently allows us to run both on one terminal as well as it allows us to pass --kill-others-on-fail which means that if one breaks (control + c on mac), the other one will also break

like image 42
Tuan Nguyen Avatar answered Dec 09 '25 10:12

Tuan Nguyen