what is ~/.npm dir for?

Steven Lu picture Steven Lu · Feb 12, 2013 · Viewed 13.1k times · Source

I have installed the global npm package jslint and it lives here

$ ls -la /usr/local/bin/jslint
lrwxr-xr-x  1 lust  admin  40 Feb 12 15:31 /usr/local/bin/jslint -> ../lib/node_modules/jslint/bin/jslint.js

$ ls -la /usr/local/lib/node_modules/jslint/bin 
total 8
drwxr-xr-x   3 lust  staff   102 Apr 16  2012 .
drwxr-xr-x  10 lust  staff   340 Feb 12 15:31 ..
-rwxr-xr-x   1 lust  staff  2330 Apr 16  2012 jslint.js

$ which jslint
/usr/local/bin/jslint

$ head -3 /usr/local/bin/jslint 
#!/usr/bin/env node

var linter = require("../lib/linter");

So it is without any doubt whatsoever at this point that jslint is in fact being run from this dir and not here:

$ ls -la .npm/jslint/0.1.9/package/bin/         
total 8
drwxr-xr-x  3 lust  staff   102 Apr 16  2012 .
drwxr-xr-x  9 lust  staff   306 Feb 12 15:31 ..
-rwxr-xr-x  1 lust  staff  2330 Apr 16  2012 jslint.js

There appear to be two copies of the package, one in /usr/local/ and one in ~/.npm. Why is there one in .npm and is it safe for me to remove it?

Answer

Trevor Burnham picture Trevor Burnham · Feb 12, 2013

~/.npm is a cache that npm uses to avoid re-downloading the same package multiple times. There's no harm in removing it. You can empty it with the command:

npm cache clean