Reputation: 1599
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?
Upvotes: 3
Views: 6558
Reputation: 1
Nodemon is primarily used for backend development with Node.js, as it monitors changes in server-side files and automatically restarts the server when changes are made. However, it is possible to use Nodemon for frontend development as well, especially in cases where you are using a tool like Webpack to build and bundle your frontend assets.
For example, if you have a frontend project that uses Webpack to compile your JavaScript, CSS, and HTML files, you can use Nodemon to monitor changes in your source files and automatically trigger a rebuild of your project whenever changes are detected. This can save you time and make your frontend development workflow more efficient.
That being said, Nodemon is not a frontend-specific tool, and there may be other tools and frameworks that are better suited for frontend development, depending on your specific needs and requirements.
Upvotes: 0
Reputation: 21
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
Upvotes: 1
Reputation: 742
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.
Upvotes: 2