viernes, 9 de enero de 2015

Node watch task problems in linux&mac

Some developer tools I'm working with lately, like node watch, listen to changes in a filesystem folder using native system APIs for this. On unix systems I had some trouble with those, but good trouble, let me explain.

In unix systems there is a limit on the number of files being watched at a time b a process. And the kernel won't allow a process to watch too many files at the same time.

This is why, we can have trouble while executing development environments based in node watch (grunt watch, gulp watch, etc) in unix (linux and mac). The name of the error has the code : ENOSPC. It mostly fails or enters in a infinite loop, for example:

grunt watch
Warning: watch ENOSPC

Solution

The solution in linux is the following:
echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p

viernes, 2 de enero de 2015

my nodejs tool can't use itself

So I have this nodejs application short-jsdoc for documenting JavaScript code. The strange thing is that If I want to use it in itself, this is, installing it in its own project, nodejs refuses to do so:
cd short-jsdoc
npm install short-jsdoc --save-dev
npm WARN install Refusing to install short-jsdoc as a dependency of itself
At first I was surprised and I still am because nodejs always install dependencies locally inside the project and so this situation could be managed easily, but on the other side, the user from irc.freenode.org#Node.js give me crucial tips:
1) Why would I want foo depend on foo since in foo I already have all the code of foo?
2) If you are publishing a npm module then you should expose a main .js file and you can always require that file using require('./') syntax. That will always work. Thanks !