Unscoped packages are always public, which means they can be searched for, downloaded, and installed by anyone. To install a public package, on the command line, run
npm install <package_name>
This will create the
node_modules
directory in your current directory (if one doesn't exist yet) and will download the package to that directory.
Note:
If there is no
package.json
file in the local directory, the latest version of the package is installed.
If there is a
package.json
file, npm installs the latest version that satisfies the
semver rule
declared in
package.json
.
Scoped public packages
can be downloaded and installed by anyone, as long as the scope name is referenced during installation:
npm install @scope/package-name
Private packages
can only be downloaded and installed by those who have been granted read access to the package. Since private packages are always scoped, you must reference the scope name during installation:
npm install @scope/private-package-name
To confirm that
npm install
worked correctly, in your module directory, check that a
node_modules
directory exists and that it contains a directory for the package(s) you installed:
ls node_modules
If there is a
package.json
file in the directory in which
npm install
is run, npm installs the latest version of the package that satisfies the
semantic versioning rule
declared in
package.json
.
If there is no
package.json
file, the latest version of the package is installed.
Like
npm publish
,
npm install <package_name>
will use the
latest
tag by default.