0

I am on OS X, I intend on upgrading my mac in the respectively near future and I am curious to know if there is a package.json or equal component to npm available to me for packages I have installed over time. That I can make sure I transfer over to a new machine when that time comes that makes re-obtaining some of these easier as I've personally forgotten many of the packages I have installed over time.

Also future proofing my problem is there any good practices for managing dependencies of ones day to day life that would making moving to a new computer or working on multiple computers easier

chris
  • 36,115
  • 52
  • 143
  • 252

1 Answers1

3
npm ls -g --depth=0

This command lists all your globally installed packages.

Using some unix utilities, we can convert the output of this command into a string that npm install can work with.

npm ls -g --depth=0 | sed '1d' | cut -c5- | tr '\n' ' '

This command gives you a space separated string of every global package you have installed, with exact version numbers. You can simply copy paste this string and run npm install -g with it on your new computer.

This works for me on npm 3.5.3. The output of the npm ls command might be different based on version number so it's possible this won't work for you. If so, either adjust the pipeline or try installing my version of npm (won't affect your other packages).

I'm not not aware of easier methods to transfer global packages between computers. When you install packages without --save, it simply downloads the folder to your global packages location.
By design, installing packages globally with package.json is out of the question as well.

Community
  • 1
  • 1
Prashanth Chandra
  • 2,672
  • 3
  • 24
  • 42