Nodemon not refreshing browser in React-Express-Node App

本秂侑毒 提交于 2019-12-03 13:38:06

nodemon is only for restarting the server when your server code changes. It has no functionality to reload your page in the browser. If you want automatic browser reload, you could, for example, run a webpack dev server in addition to your nodemon. webpack dev server is able reload the page in the browser when your client code changes, it can even update the page in the browser without a full page reload, if you use its hot module reloading feature.

For those needing to use nodemon and reload browser on change as well, I replied here https://stackoverflow.com/a/51089425/7779953

Solution is Nodemon + Browser Sync + Gulp + Express server

in package.json

"scripts": {
   "start": "nodemon server.js -e html,js,css"
},

in server js

var reload = require('reload')

app.listen(3000, () => {

  console.log(`Listening on port 3000`);
})

reload(app);

in index.html

<body>
  <h1>ron</h1>
  <script src="/reload/reload.js"></script> <!-- it's necessary -->
</body>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!