How to Increase the File Watcher System Limit in Node

  • by Matt (3)
  • Time to complete: 2 minutes

This short guide will show you how to increase the system limit for file watchers in NodeJS.

1

When using node to watch a project with something like nodemon, there will usually be an error like ENOSPC: System limit for number of file watchers reached...

This is due to system defaults and this limit can easily be increased with a few simple commands.

This can occur when trying to start up any kind of project that watches files for things like hot reloading as well as any piece of software that would want to keep watch on files to detect changes and take actions based on those changes such as Visual Studio Code,

2

“Visual Studio Code is unable to watch for file changes in this large workspace” (error ENOSPC)

When you see this notification, it indicates that the VS Code file watcher is running out of handles because the workspace is large and contains many files.

[bat] A cat clone with wings.

The current limit can be viewed by running cat or, even better, bat which as they say themselves, [bat] A cat(1) clone with wings which just means it has auto syntax highlighting, better output formatting in general, is available on Docker, Mac OSX and basically all flavors of Linux.

$ cat /proc/sys/fs/inotify/max_user_watches
# returned value:  8192

The limit can be increased to its maximum (524288) by editing /etc/sysctl.conf and appending this line to the file.

fs.inotify.max_user_watches=524288

You can do by opening up your favorite text editor and adding the line or by running:

$ echo 'fs.inotify.max_user_watches=524288' | sudo tee -a /etc/sysctl.conf

The value appended will be printed to the console if the append worked.

The new value can then be loaded/sourced by running:

$ sudo sysctl -p

This should be the only time you have to do this until you have to set up a new system again.