Home Interests Node

How to Increase the File Watcher System Limit in Node

howchoo
howchoo   (467)
September 29, 2023
5 minutes

Share

Interests
Posted in these interests:
node • 1 guides
sysadmin • 1 guides

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

1 – Why do I see this ENOSPC file watch limit error?

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 – Increase the limit

“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.

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.

3 – Bonus: Sync VS Code Settings

We’re going to save you some time here. Definitely sync your VS Code settings across your computers to save you big time in the end!

How to Sync VS Code Settings Across Your Machines
It’s your setup, wherever you are…

howchoo

 467 guides

Introducing Howchoo, an enigmatic author whose unique pen name reflects their boundless curiosity and limitless creativity. Mysterious and multifaceted, Howchoo has emerged as a captivating storyteller, leaving readers mesmerized by the uncharted realms they craft with their words. With an insatiable appetite for knowledge and a love for exploration, Howchoo's writing transcends conventional genres, blurring the lines between fantasy, science fiction, and the surreal. Their narratives are a kaleidoscope of ideas, weaving together intricate plots, unforgettable characters, and thought-provoking themes that challenge the boundaries of imagination.

Discover interesting things!

Explore Howchoo's most popular interests.

Explore