1

I constantly need to switch between multiple computers at work, and I want to sync my globally installed npm packages as a dotfiles to make it portable.

Where can I find such a file that can represent all my globally installed npm packages and I can easily use it to install again in different computer?

Edit

I forgot to mention that I want to put my dotfiles that has the information of all my installed packages on Git.

John Winston
  • 1,260
  • 15
  • 30
  • According to the edit, what you need is to install the libraries normally, not global, that'll make the `packages.json` file contain them, and you just run with `npx` from each project you install them. – Alejandro Apr 29 '21 at 16:27

2 Answers2

0

Node doesn't makes any "global" install in the system, other than writing to its own install folder. We can say it's already "portable". All that a global npm install really does is to write to the node_modules folder where the node binary resides instead of the current folder. So, copying the whole node folder would suffice to make it portable. This is what you really download when you get the .zip distribution from the official website.

Apart from that, the installer sets the PATH environment variable to point to the node folder, so you can just invoke on the command line by node <something> instead of "c:\program files\node\node.exe" <something>.

Alejandro
  • 7,290
  • 4
  • 34
  • 59
  • But I don't want to put a `node_modules` onto my git. I guess this will be my last resort. – John Winston Apr 29 '21 at 15:50
  • You didn't ask about git, the question was about making node and npm portable, copying the whole binary folder is that answer. What has Git to do with that? – Alejandro Apr 29 '21 at 16:11
  • Sorry I forgot to mention it. I want to only push a file that stores information of all packages to Git, so that I can easily download it on the other environment. – John Winston Apr 29 '21 at 16:15
0

rather than addressing each of your questions, i will try to answer you from a different angle.

when npm install a package, it (or any of its dependencies) might be complied specifically to your platform-architecture. if you (in some magic way) port the package (or any of its dependencies), the designated platform-architecture must be the same.

anyhow, quoting from this answer:

It's not possible to specify dependencies as "global" from a package.json. And, this is by design as Isaac states in that feature request you referenced:

Yeah, we're never going to do this.

Mr.
  • 9,429
  • 13
  • 58
  • 82