Fix for 100% CPU usage by node.js

If you are on MacOs and you don't have installed fsevents, you might see a spike in CPU usage when running projects which watches the filesystem changes, especially projects like Webpack. To fix the issue, install fsevents or rebuild using fsevents.

I was seeing a really high spike in CPU usage while running projects which used node.js, in most cases the CPU usage was way above 100%.

This issue can be really intimidating when you have watchers which watch for file changes, like for eg: webpack.

As usual, my google-fu landed in a couple of Github issues where users mentioned the same problems.

Whats the fix.?

TL;DR install/re-install fsevents

  • Install fsevents if you are using MacOS and have not already installed it
npm install fsevents
  • Rebuild if you had installed fsevents but recently upgraded node version.
npm rebuild fsevents

Hope this helps someone. :spock_hands:

References:

https://github.com/nodejs/node/issues/6459
https://github.com/webpack/webpack/issues/701
https://github.com/webpack/webpack-dev-server/issues/172
https://github.com/paulmillr/chokidar/issues/447