4

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

Laurent Meyer
  • 2,766
  • 3
  • 33
  • 57
  • 1
    The latest version of NPM will share dependent modules rather than nest separately. – jfriend00 Apr 19 '16 at 06:56
  • This is a great suggestion, but it seems that npm doesn't do this automatically yet. Run npm dedupe manually. https://docs.npmjs.com/cli/dedupe – TinkerTank Apr 19 '16 at 07:13

1 Answers1

3

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 .

Community
  • 1
  • 1
TinkerTank
  • 5,685
  • 2
  • 32
  • 41
  • So sorry for the late upvote, I will test first you comment `npm dedupe` and then try the filesystem. 1 & 2 looks really hacky (it's fine for a personal project but mine is running in prod...) – Laurent Meyer Apr 23 '16 at 12:56