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
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.
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.
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
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.
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.
[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.
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.
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
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'
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.
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.
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.
Related
I have a Javascript project set using React.js. Npm install for nodemon package version 2.0.7 fails with following errors:
It seems that the installation is trying to spawn Git Bash but without success.
Should the installation spawn bash.exe from the folder C:\Program Files\Git\bin instead
of C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Git\Git Bash?
Same error message happens when running npm run dev to start the Node server:
Same errors happen when run from Git Bash.
Earlier nodemon version 1.10.0 installation succeeds with no errors.
I have
OS Windows 10
npm version 6.14.8
node version 14.15.0
git version 2.28.0.windows.1
I think my Git is set to environment path variable correctly.
What could be causing this error?
I installed npm-run-all and also configured the environment variable (which may or may not be not required) on my Windows machine but am getting an error:
'npm-run-all' is not recognized as an internal or external command,
operable program or batch file
I am trying to build my current project with npm run build which includes the script where the error is thrown:
npm-run-all -p build-css build-webpack
Do I have to do any additional things to make it run?
Make sure the npm-run-all is in your package.json devDependencies.
If npm-run-all is present in your package.json, run npm i
If not present install it, run: npm i npm-run-all -D
If error is still present, follow these steps:
Remove node_modules folder: run rm -rf node_modules
Install all dependecies: run npm i
Hope this helps!
You may just need to run the following command first (from the directory with the package.json file)
npm install
Please do that like this.
npm i npm-run-all -g
And then this issue will be fixed.
You have a couple of options here, besides installing npm-run-all as a global package as suggested by #Vaibhav in the comments:
1) Create an NPM script
The package.json file has a scripts section which can used to define shortcuts for anything you need to run while you're working on your app. There are some pre-defined scripts, like run or test than can be executed with simply npm start/npm test or you can define anything you like and then run it with npm run my-script-name. You could try:
{
"scripts": {
"start": "npm-run-all -p build-css build-webpack"
}
}
Any NPM module referenced here "just works" (i.e. the path to the executable is resolved under the hood by NPM)
2) NPX
In newer versions of NPM (i.e. >= 5.2 or so), the "NPX" executable is provided. This has a similar effect to running commands inside an NPM script. You would run:
npx npm-run-all -p build-css build-webpack
Again, the path would be automatically resolved.
If you have an older NPM install, you can also install it separately:
npm install -g npx
npm install -g npm-run-all
Works for me.
Double check if npm-run-all is in your package.json devDependencies.
I had same problem while using code editor Brackets.
To resolve the error, I did the following steps.
Add nodejs new system variable to your PC under Control Panel -> System -> Advanced System Settings
;C:\Program Files\nodejs\
After that, re-run command:
npm
I don't know if this would help anyone, but I got this error because I was doing nodemon server.js instead of nodemon server/server.js. I wasn't in the right folder!
Did you reopen the terminal after you installed node?
If you have installed npm with the current terminal window open. Your terminal window will not have loaded the latest path settings (with npm location) to find the npm application to run the command. In this case try below steps .
Try closing the current terminal session.
Reopen a new session.
Try the command again ( will pick up the new path settings with npm installed)
This worked for me.
npm audit fix --force
Also you can try downgrading your autoprefixer, seems version 10.0.0 doesn't work well with postcss
npm i autoprefixer#9.8.6
I am getting an error while running my server file using nodemon. When I type the command nodemon, I get the following output.
[~/D/g/sendMail-lib|3.6.5]
‹master*› »»»» nodemon 0|15:35:32
[nodemon] 1.17.5
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: *.*
[nodemon] starting `node server.js`
[nodemon] Internal watch failed: ENOSPC: no space left on device, watch '/home/abdus/Documents/github/sendMail-lib/3808.txt'
[~/D/g/sendMail-lib|3.6.5]
‹master*› »»»»
Additionally, it creates almost 4000 blank text files(1.txt, 2.txt and so on).
I tried this commands but the problem still persists.
I am on Arch Linux with Node version 10.5.0, NPM version 6.1.0 and Nodemon version 1.17.5.
Just ask me if you need any more information.
I had the same problem.
Run nodemon as sudo.
$ sudo nodemon
Or
# nodemon
Most issues I run into with Arch are solved by just running as root. ;)
echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p
Taken from here.
This is effectively a rights problem, but you don't need to use sudo, just give the user that run nodemon the rights to write to the build directory
an exemple with permissive rights (we use nodemon, so I assume we are in dev)
sudo chmod a+rwX my-application-dir
I installed nodemon locally so, I created an "npm start" script and run it as root
like so: sudo npm start
I got this error when trying to run npm start with a start script that looked like this:
"start": "nodemon server.js"
It seems that I had a global installation of nodemon, but not a local version in my project's node_modules. Once I ran npm install nodemon, it installed it locally and worked without requiring root permissions.
nodemon: v1.18.5
OS: ubuntu 18.04
I'm trying to run Telescope (a meteor app) on an Ubuntu 16.04 server. I follow the instructions in the readme:
curl https://install.meteor.com/ | sh
git clone git#github.com:TelescopeJS/Telescope.git
npm install
The first two commands run without an error, but the last command end in Killed:
$ npm install
npm WARN deprecated cross-spawn-async#2.2.4: cross-spawn no longer requires a build toolchain, use it instead!
extract:moment → gunzTarP ▐ ╢█████████████████████████████████████████████████░░░░░░░░░░╟
Killed
Since it doesn't give any information I'm unsure what could be wrong here. Does anybody know how I can solve this? All tips are welcome!
[EDIT]
Using the tip of #Mills in the comments I first ran npm install cross-spawn and then npm install again. This fixed the npm install issue, but when I now try to run the app using meteor it ends with "Killed" again:
$ meteor
Killednloading meteor-tool#1.3.2_4... |
Any more ideas?
I haved same problem, my solution:
sudo /bin/dd if=/dev/zero of=/var/swap.1 bs=1M count=1024
sudo /sbin/mkswap /var/swap.1
sudo /sbin/swapon /var/swap.1
this commands changed configuration for swap
I am running into a similar issue installing npm packages and getting the message "Killed" and a non-zero exit status. For my scenario, it was because my system was running out of memory and I had no swap configured. Configuring swap fixed my problem.
To solve this issue on 14.04 and 16.04:
sudo fallocate -l 1G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
sudo swapon --show
sudo cp /etc/fstab /etc/fstab.bak
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab
sudo sysctl vm.swappiness=10
echo 'vm.swappiness=10' | sudo tee -a /etc/sysctl.conf
sudo sysctl vm.vfs_cache_pressure=50
echo 'vm.vfs_cache_pressure=50' | sudo tee -a /etc/sysctl.conf
This will create a swap file of 1GB
Trying running npm install cross-spawn and then npm install again to see if that works. It looks like whats happening is when you run npm install npm looks inside your package.json provided by telesope and is running a deprecated package
I got the same issue when running npm run build in a VM with a single core CPU and 1GB RAM. Increasing the RAM to 4GB resolved this issue.
or you can do the hardway do npm install somewhere else. i did it on my windows and uploaded al the nodemodules dir with ftpclient to the server. that worked for me
I got the same error on DO. I just increased size of CPU and RAM
I'm currently using node along with nodemon. Then I got to thinking it might be sometimes nice to use an inspector with node so have started using node-inspector
However, is it possible to run both at the same time?
Normally to run nodemon I would use:
nodemon server.js
//and similarly
node-debug server.js
I have also tried:
nodemon --debug http.js
But sadly this didn't work either.
But both together!?
If you want to run them as one command this works for me: node-inspector & nodemon --debug app.js (replacing app.js with the name of your script). If things get all mucked up you will occasionally have to kill node-inspector manually, but running the command this way gives you the option of running rs to restart nodemon manually if needed. HTH
You would start your server with nodemon --debug server.js and then you'll need to run node-inspector in a separate terminal window unless you push nodemon to the background.
For those that want an OS-independent solution and no hacks for windows, etc.
You can use npm-run-all which is a CLI tool that allows running multiple npm scripts in parallel or sequentially. So you'd set your package.json as so:
"scripts": {
"start": "npm-run-all --parallel lint start:debug start:server",
"lint": "eslint . --ext .js",
"start:debug": "node-debug server.js",
"start:server": "nodemon server.js"
}
And then from CLI, you do: npm start
Caveat: from my experience running nodemon and node-debug together leads to weird node-inspector behaviors sometimes. So i've since opted to remove nodemon from my scripts when debugging and relying on node-inspectors save-live-edit feature to change files on the fly.
I could not get nodemon to play nice with node-inspector. After one change it would restart but after that no more. Maybe it is because I am using docker containers.
The easiest way to reload the application is to let node-inspector do it (I know this is not an answer to having both run but it worked for me).
Start your application in the following way:
node-inspector --save-live-edit & \
node --debug /app/server.js
As I'm running on Linux I wrote a bash script based from rpaskett's answer so that you don't need to remember that awkward command every time.
However I noticed in a comment you're running Windows. Here are some options you have:
You could convert the bash script to Windows batch and save it as C:\Windows\System32\node-DEV.bat. I did it and it works on my Windows PC:
#echo off
echo Starting DEV environment for %1
start node-inspector
nodemon --debug %1
Then you should be able to run node-DEV server.js.
Another option; you could run something like nodedev which was written in Node.js thus platform independent, although it looks like it hasn't been updated in a while.
Or you could even run the bash script within a Cygwin environment if you had one handy.
A hacky fix for Windows users running a bash shell:
First, add node-inspector to your Path.
(You can find where npm is installing packages with npm list -g)
Then use this command in bash, or add it to your npm scripts:
START /B node-inspector && nodemon --debug server.js
START /B being the windows command to run in the background.
You must be install node-inspector and nodemon using:
npm install -g nodemon
npm install -g node-inspector
To run in Windows, make a new .bat file and add the folowing lines:
#echo off
echo Starting developer enviroment of the file %1
start nodemon --debug-brk %1
node-debug %1
And run:
node_desarrollo.bat "name of the file to run.js"
If ran with a error:
Error: listen EADDRINUSE :::5858
at Object.exports._errnoException (util.js:855:11)
at exports._exceptionWithHostPort (util.js:878:20)
at Agent.Server._listen2 (net.js:1237:14)
at listen (net.js:1273:10)
at Agent.Server.listen (net.js:1369:5)
at Object.start (_debug_agent.js:21:9)
at startup (node.js:72:9)
at node.js:980:3
Its normal because the node-inspector need to open that port to connect but because the nodemon --debug-brk %1 was opened the 5858 port its cannot open and show the EADDRINUSE :::5858 error, note that the flag --debug-brk of nodemon it's necessary to make a breakpoint on the first line. Try modifying the file.js after run the .bat and look the changes reflected on the debugger. This debugger reboots and show the changes done in the file.js. Happy coding JS!!!
{
"scripts": {
"dev": "npx nodemon --exec \"node --inspect --debug-port=0.0.0.0 src/index.js\""
}
}