How is use of npm to install global packages that don't even get used in Node applications justified?

后端 未结 4 1165
小鲜肉
小鲜肉 2021-01-06 00:52

My knowledge of npm is this:

It is a package manager for Node.js applications. What this means is that when you need someone else\'s librar

4条回答
  •  遥遥无期
    2021-01-06 01:43

    npm install is a complicated command -- it has (at least) three major functions:

    1. From inside of a Node package (that is, a directory with a package.json file, or some subdirectory of it), running npm install installs all of that package's declared dependencies. It sticks these downloaded packages inside of a node_modules directory, and they are all available by the application's JavaScript code.

    2. Again, from inside of a node package, running npm install will download and install a named package from the npm package repository. It will, again, place it in the node_modules directory, so that it is available to that application.

    3. From anywhere, running npm install -g will download and install a named package globally. This means that it gets installed to your system's node_modules directory, and is available for all node packages to use.

    The third usage, with -g, is also used for command-line utilities (as opposed to libraries). When installed with -g, packages can do things like installing new commands in /usr/local/bin, or installing man pages. These commands are then available to be run from a shell.

    This is what cca does when you install it, and is the reason that we recommend installing with -g; so that you can use the cca command to create applications from anywhere, not because it is a kind of packaging utility.

提交回复
热议问题