You can install a package locally if you want to depend on the package from your own module, using something like Node.js
require. This is
npm install’s default behavior.
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.
package.jsonfile in the local directory, the latest version of the package is installed. If there is a
package.jsonfile, npm installs the latest version that satisfies the semver rule declared in
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:
If there is a
package.json file in the directory in which
npm install is run, npm instalsx the latest version of the package that satisfies the semantic versioning rule declared in
If there is no
package.json file, the latest version of the package is installed.
npm install <package_name> will use the
latest tag by default.
To override this behavior, use
npm install <package_name>@<tag>. For example, to install the
example-package at the version tagged with
beta, you would run the following command:
npm install [email protected]