Reputation: 289
This is not similar nor does it answer question: copy npm global installed package to local
Basically I want to tell NPM, look at what I have installed globally, and install that locally.
I'm not interested in the symlinks, but if above is not possible, could I use a single symlink to node_modules instead of a symlink for each package?
Upvotes: 1
Views: 253
Reputation: 28687
You can parse the output of node ls -g --depth 0
and npm install
the resulting list of packages.
npm i -S -dd $(npm ls -g --depth 0 | tail -n +2 | cut -c 5- | tr '\n' ' ')
Run this command in the directory of the package that you wish to install global packages to.
Explanation:
npm i -S -dd
Shorthand for npm install --save --verbose
. The -S
is unnecessary on recent npm versions that save installed packages to package.json by default.
npm ls -g --depth 0
List first-level global packages.
tail -n +2
Remove the first line from the output.
cut -c 5-
Remove the first four characters from each line in the output.
tr '\n' ' '
Combine each line to place all packages on one line, separated by spaces.
Upvotes: 1