184

I just installed Node.js on my Ubuntu 14.04 operating system for the first time. I also installed npm. The next step in my installation process was installing nodemon. This all worked out fine.


But, when I run nodemon by typing nodemon app.js in my command line, I get the following error...

[nodemon] 1.8.1 [nodemon] to restart at any time, enterrs [nodemon] watching: *.* [nodemon] startingnode app.js [nodemon] Internal watch failed: watch ENOSPC

In the command line below the error...

alopex@Alopex:~/Desktop/coding_dojo/week-9/javascript/node/testing_node$ Hello World

Why is this happening? Is this normal behavior for nodemon? If not, how can I fix it?


Side notes...

1) app.js is a Javascript file with console.log(111) inside of it.
2) node version is v0.10.25
3) npm version is 1.3.10
4) nodemon version is 1.8.1
5) ubuntu version is...

Distributor ID: Ubuntu
Description:    Ubuntu 14.04.3 LTS
Release:    14.04
Codename:   trusty
Erik Åsland
  • 9,542
  • 10
  • 30
  • 58
  • Possible duplicate of [Grunt watch error - Waiting...Fatal error: watch ENOSPC](http://stackoverflow.com/questions/16748737/grunt-watch-error-waiting-fatal-error-watch-enospc) – Andre Figueiredo Feb 02 '17 at 14:39

11 Answers11

565

It appears that my max ports weren't configured correctly. I ran the following code and it worked...

echo fs.inotify.max_user_watches=582222 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p

What this command does is to increase the number of watches allowed for a single user. By the default the number can be low (8192 for example). When nodemon tries to watch large numbers of directories for changes it has to create several watches, which can surpass that limit.

More explanation of how it solves the problem:
echo fs.inotify.max_user_watches=524288 it increase the number of watches of nodemon as you made some changes in your project and
sudo tee -a /etc/sysctl.conf && sudo sysctl -p is sysctl command for configure kernel parameters at runtime.
More on https://wiki.archlinux.org/title/kernel_parameters

You could also solve this problem by:

sudo sysctl fs.inotify.max_user_watches=582222 && sudo sysctl -p

But the way it was written first will make this change permanent.

Vinicius Cardoso
  • 666
  • 8
  • 23
Erik Åsland
  • 9,542
  • 10
  • 30
  • 58
51

On running node server shows Following Errors and solutions:

nodemon server.js

[nodemon] 1.17.2

[nodemon] to restart at any time, enter rs

[nodemon] watching: .

[nodemon] starting node server.js

[nodemon] Internal watch failed: watch /home/aurum304/jin ENOSPC

sudo pkill -f node

or

echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p
Community
  • 1
  • 1
Mani Abi Anand
  • 1,245
  • 11
  • 10
  • 5
    Be careful with the 'sudo pkill -f node' command. It force kills all running node applications. Some apps (e.g. Atom, vscode) depend on node and therefore this command could potentially crash those apps and you could lose work. Also it is not guaranteed to have effect anyway. Second one is better. – Tafel Jun 02 '21 at 08:42
33

Erik, You can just kill all the other node processes by

pkill -f node

and then restart your server again. It'll work just fine then.

pawanpandey392
  • 849
  • 12
  • 16
25

As per discussion over here, ENOSPC means Error No more hard-disk space available. Reason why this much memory required by nodemon or gulp-nodemon (in my case) is that it was watching contents of a folder which it shouldn't. To fix that nodemon has ignore setting that can be used to tell nodemon what not to watch. Have a look at nodemon sample config here.

Zubair Alam
  • 8,739
  • 3
  • 26
  • 25
16
[nodemon] Internal watch failed: watch /home/Document/nmmExpressServer/bin ENOSPC
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! nmmexpressserver@0.0.0 start: `nodemon ./bin/www`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the nmmexpressserver@0.0.0 start script.

This is the error I got when running nodemon ./bin/www.

The solution was closing an Atom window that had a entire directory of folders open in the project window.

I don't know why, but I'm assuming Atom and nodemon use similar processes to watch files/folders.

divinedragon
  • 5,105
  • 13
  • 50
  • 97
codeinaire
  • 1,682
  • 1
  • 13
  • 26
  • 2
    That was exactly my problem. I happeed to launch atom from the project's install directory. I closed atom, launched it from a different dir and the problem went away. – Ya. Jul 22 '18 at 19:16
  • In my case, the same was happening on Sublime in Ubuntu. When I closed the IDE, I could run it properly. Any tips about it? – Shad Sep 20 '18 at 19:42
  • I've not tried to replicate it to see if it has been fixed. – codeinaire Sep 21 '18 at 23:30
  • Thanks. Mine can work after I close Gitkraken. This is a strange problem. So that means we can not have two processes monitoring the same folder? – Zhang LongQI Nov 09 '18 at 09:21
  • It was Nextcloud client here - that uses a ton of inotify watches. Thanks, y'all! – Bill McGonigle Nov 23 '18 at 00:49
  • At my is case was sublime editor running. I closed it and everything works fine. – Marcelo Rebouças Jun 08 '20 at 22:47
12

Add a nodemon.json configuration file in your root folder and specify ignore patterns for example:

nodemon.json

{
  "ignore": [
    "*.test.js", 
    "dist/*"
  ]
}
  • Note that by default .git, node_modules, bower_components, .nyc_output, coverage and .sass-cache are ignored so you don't need to add them to your configuration.

Explanation: This error happens because you exceeded the max number of watchers allowed by your system (i.e. nodemon has no more disk space to watch all the files - which probably means you are watching not important files). So you ignore non-important files that you don't care about changes in them for example the build output or the test cases.

Ahmed Soliman
  • 365
  • 1
  • 4
  • 12
6

in my case closing the visual studio code then starting the server did the trick

Operating system - ubuntu 16.4 lts

node.js version - 8.11.1

npm version - 6.0.0

Vishal Verma
  • 163
  • 2
  • 2
4

Instead of specifying a list of directories to ignore (e.g. negative), you can also specify a list of directories to watch (e.g positive):

nodemon --watch dir1 --watch dir2  dir1/examples/index.js

In my particular case, I had one directory I wanted to watch and about nine I wanted to ignore, so specifying '--watch' was much simpler than specifying '--ignore'

vt5491
  • 2,254
  • 2
  • 22
  • 34
  • Thanks, my nodemon was restarting multiple times in a docker container and taking forever to reload the server. Added the watch for my src folder and it's lightning fast. – Devin Fields Nov 15 '21 at 06:26
2

There must be a better way of solving this, than what I suggest. I hope some experts land on this page. Also note that I was working on a development server and thus could afford to kill all processes of node. This may not be what you want.

I followed the answer of @zubair-alam and got it fixed for the first time. I added the "ignore" to the package.json (Even though the referred link says it is the default).

 ........ Before
  "ignore": [
    ".git",
    "node_modules/**/node_modules"
  ],
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "nodemon ./index.js --exec babel-node -e js"
  },
 ........ After

However the error returned again as soon as I added a new file to the folder. I was working on Linux, so I basically killed all process related to node, by saying the following.

killall node

and then restarted npm by saying. The server started without errors.

npm start

You will have to change the killall command using a command specific to your operating system. See this discussion.

Amit
  • 2,018
  • 1
  • 8
  • 12
1

I had the same error, but in Ubuntu 14.04 inside Windows 10 (Bash on Ubuntu on Windows). All I did to overcome the error was to update the Creators update, which then allowed me to install 16.04 version of Ubuntu bash and then after installing newest version of node (by this steps) I installed also the newest version of npm and then the nodemon started to work properly.

Šimon Hrabec
  • 626
  • 1
  • 7
  • 10
1

Try reopening VS code or Atom with more specific directory where your app.js is present. I had a lot of folders opened and this problem occured. But once I opened my specific folder and tried once again, it worked.