195

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
1

11 Answers 11

583

It appears that my max ports weren't configured correctly. Here is the fix.

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.

Sign up to request clarification or add additional context in comments.

19 Comments

Could someone explain a little more what this does and elaborate on why it could help?
@Hinrich, it is just a guess, i think nodejs watches the file system changes via inotify library. I think there is a limit per user for the max number of watches, which this setting changes to a greater value.
@devrimbaris Correct!
It has just happened to me after going from Ubuntu 14.04 to Ubuntu 16.04. Your solution worked for me as well. Thank you
Put that on /etc/sysctl.d/90-override.conf if you're on Arch
|
57

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

1 Comment

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

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.

5 Comments

Downvote because this also caused my Visual Studio Code windows to freeze.
this was working like a charm...until now! Now its ineffective, getting same error.
If you have multiple things running with node, this will cause them all to stop. This is especially troublesome if you have both a client and server running.
This isn't an answer, this is a comment
This is useful only to run in a isolate environment like dedicated node docker
26

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.

2 Comments

Good job, this is the root cause.
This was the reason for me. Spot on explanation of ENOSPC. Thank you.
16
[nodemon] Internal watch failed: watch /home/Document/nmmExpressServer/bin ENOSPC
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] start: `nodemon ./bin/www`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] 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.

6 Comments

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.
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?
I've not tried to replicate it to see if it has been fixed.
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?
It was Nextcloud client here - that uses a ton of inotify watches. Thanks, y'all!
|
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.

Comments

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

2 Comments

It seems that he was not using visual studio.
Although this doesn't directly answer the question (because the question doesn't involve VS Code), this did solve my problem.
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'

1 Comment

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

Comments

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.

Comments

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.