When should you use npm with the -g flag and why?

I recently started using npm to manage js packages. Although I have a fair understanding of package management in different enivronments (say using apt, rvm / gem, pythonbrew / virtualenv / pip), I don’t quite understand how npm fits completely.

I would like to know more about how the -g flag works and why I should use it. As with most blogs and wikis, they refer to the use of "-g" during installation without explanation, and I understand that these packages are installed globally.

  • But why should I always install these packages globally?
  • What does it mean to install these packages without the "-g" flag?
  • What should I do with installed packages locally, say, isolated for different projects?
  • How can I make a list of npm packages used in a project and lay it out in a project if I need to check it using version control (if possible at all)?
+73
npm
Jan 18 '12 at 12:18
source share
1 answer

-g is the global installation flag as described in this answer . He is covered in detail in this blog post node .

Thumb rules:

  • Install globally if the package provides command line tools
  • Install locally if you are using the package as part of your application.
  • Set globally and locally if both use cases apply.
+75
Jan 21 2018-12-12T00:
source share



All Articles