How to list all the Node.js modules I have linked with npm

I am looking for a command that will list the names of global modules that I have npm link'd to local copies, also listing the local path.

In fact, a list of all globally installed modules would be even better, with the npm link'd ones flagged somehow.


Solution 1:

To list all globally linked modules, this works (documentation https://docs.npmjs.com/cli/ls):

npm ls -g --depth=0 --link=true

I had to update the version of npm on my machine first, though:

npm install npm@latest -g

Solution 2:

Did you try just listing the node_modules directory contents (e.g., ls -l node_modules | grep ^l)? They're normal symbolic links.

If you really need to find all symbolic links, you could try something like find / -type d -name "node_modules" 2>/dev/null | xargs -I{} find {} -type l -maxdepth 1 | xargs ls -l.

Solution 3:

A better alternative to parsing ls is to use find like this:

find . -type l

You can use -maxdepth 1 to only process the first directory level:

find . -maxdepth 1 -type l

You can use -ls for additional information.

For instance, for finding Node.js modules that are npm linked:

find node_modules -maxdepth 1 -type l -ls

Here's an article why parsing ls is not the best idea.