If you want a nice colored output from npm list
, you may like:
\ls -F node_modules | sed -n 's/@$//p' | xargs npm ls -g --depth 0
which gives in my current playground directory:
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
`-- [email protected]
It makes a few assumptions, but it should work in most cases, or be easy to adapt with the explanations below.
- use
\ls
to bypass possible aliases on your ls
command
- the
-F
option adds an '@' indicator for links
- the
sed
command selects those links and removes the indicator
- the
xargs
part passes previous output as arguments to npm ...
npm
is invoked with
list
or ls
to list modules with versions
- replace with
ll
to get details about each listed module.
-g
for the global modules and
--depth 0
for a shallow listing (optional)
--long false
(default with 'list').
Issue: for some reason npm gives extraneous entries for me at the moment (non colored). They would be those I had "npm unlink"ed.
For "a list of all globally installed modules" in current npm path, you just do
npm list -g
For further needs you may want to have a look at
npm help folders
You cannot follow symlinks backwards unless you scan your whole filesystem and (then that's not a npm specific question).
For quickly finding files and directories by name, I use locate
which works on an index rebuilt usually once a day.
locate '*/node_modules'
and start working from there (you may want to refine the search with --regexp
option.
npm -g ls
should list all global modules, but I don't know if it lists linked modulesnpm link
'd. I need a way to keep track.