Search code examples
linuxnode.jsnpmnpm-installinode

Lots of Inodes with Node.js


It is a question related to programming but more on the server administration side.

I have a server with 256K INodes available (which should be enough) but, on the other side, I have 5 projects running on this server with a lots of node dependencies (and lots of nested dependencies). With the npm install of these 5 projects, I use 70% of all available inodes (176215 of 251844 to be precise).

My question is:

Is there a way to compress the node deps? To have more data per file but less files?

Thanks


Solution

  • I do not know of an automatic way of reducing the number of files in node_modules (which is where npm stores its dependencies.) However, I can think of some options to reduce the inode use.

    1) If there are shared dependencies (of the same version-number) between these projects, you can symlink some dependencies from one project into the other. If you get a dependency with lots of nested dependencies, this can really save quite a few inodes. (untested)

    2) Another alternative, if there are lots of shared dependencies, would be to copy the node_modules of project 1 to project 2 with cp -l. In this case each copy would be a hardlink to the same file, not using any additional inodes. After that, run npm install && npm prune in project 2 to download any changes / additional dependencies. (also untested)

    3) However, both options are hacky, and might or might not give you hard-to-debug problems later, after copy-ing, after restoring a backup, etc. The real solution would be to re-create the filesystem with more inodes. For ext4, this can be done with mkfs.ext4 -i . See https://unix.stackexchange.com/questions/26598/how-can-i-increase-the-number-of-inodes-in-an-ext4-filesystem .