Reputation: 9802
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, enter
rs
[nodemon] watching: *.*
[nodemon] starting
node 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
Upvotes: 193
Views: 197384
Reputation: 9802
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.
Upvotes: 581
Reputation: 2128
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.
Upvotes: 2
Reputation: 71
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.
Upvotes: 1
Reputation: 163
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
Upvotes: 6
Reputation: 1335
nodemon server.js
[nodemon] 1.17.2
[nodemon] to restart at any time, enter
rs
[nodemon] watching: .
[nodemon] starting
node server.js
sudo pkill -f node
echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p
Upvotes: 57
Reputation: 899
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.
Upvotes: 34
Reputation: 1874
[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.
Upvotes: 16
Reputation: 365
Add a nodemon.json
configuration file in your root folder and specify ignore patterns for example:
nodemon.json
{
"ignore": [
"*.test.js",
"dist/*"
]
}
.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.
Upvotes: 12
Reputation: 2304
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'
Upvotes: 4
Reputation: 885
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.
Upvotes: 1
Reputation: 8947
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.
Upvotes: 26