Understanding npm-install, npm-install-ci-test, and npm-install-test CLI Commands
In the previous tutorial we looked at npm's hook and init commands, in this tutorial we will examine how npm-install, npm-install-ci-test and npm-install-test commands.
Npm-install
The npm install command is used to install packages.
Synopsis
Description
This command will install a package, and all the packages that the package depends on. In the case where the package contains a package-lock or shrinkwrap file, it will control the installation of dependencies, however the npm-shrinkwrap.json will take precedence if both files exist.
- npm install (in package directory, no argument):
- npm install <folder>:
- npm install <tarball file>:
- npm install <tarball url>:
- npm install [<@scope>/] <name>
- npm install [<@scope>/] <name>@<tag>:
- npm install [<@scope>/] <name>@<version>:
- npm install <git remote url>
This command will install all the dependencies found in the local node_modules folder, if you set your NODE_ENV environment variable to production, it will not include the devDependencies in the installation.
This command will install the package in the directory as a symlink in the current project. The dependencies will be installed before it is linked. In the case where <folder> sits inside the root of your project, its dependencies can be hoisted to the toplevel node_modules as they would for other types of dependencies.
This will install a package that is sitting on the filesystem. To link a dev directory into your npm root, you can easily do this, using npm link.
This command fetches the tarball url, and then installs it. To distinguish between this and other options, the argument has to start with "http://" or "https://"
This command will perform a <name>@<tag> install, where <tag> represents the tag config.
In most of the cases, this installs the version of the modules tagged as latest on the npm registry.
This command will install the version of the package that is referenced by the specified tag. If there is no existing tag in the package's registry data, the command will fail.
Here is an example:This command installs a version of the package that matches the specified version range. It will follow the same rules required to resolve dependencies described in the package.json.
An example is shown below:
This will install the package from the hosted git provider, it clones the url with git. When you specify a full git remote url, only that url is attempted.
The accepted protocols are: git, git+ssh, git+http, git+https, and git+file
Here is a list of git environment variables that are recognized by npm and will be added to the environment when running git:
o GIT_ASKPASS o GIT_EXEC_PATH o GIT_PROXY_COMMAND o GIT_SSH o GIT_SSH_COMMAND o GIT_SSL_CAINFO o GIT_SSL_NO_VERIFY
Here is an example:
- npm install <githubname>/<githubrepo>[#<commit-ish>]:
- npm install github:<githubname>/<githubrepo>[#<commit-ish>]:
This will install the package at https://github.com/githubname/githubrepo by attempting to clone it using git.
In the case where #<commit-ish> is provided, it will be used to clone exactly that commit. if your commit-ish has the format #semver:<semver>, then <semver> can be any valid semver range or exact version, then npm will look for any tags or refs that matches that range in the remote repository, in the same way it would for a registry dependency.
- Npm install bitbucket:<bitbucketname>/<bitbucketrepo>[#<commit-ish>]: This will install the package at https://bitbucket.org/bitbucketname/bitbucketrepo by attempting to clone it using git. If you provide #<commit-ish>, it is used to clone exactly that commit. Here is an example:
- npm install gitlab:<gitlabname>/<gitlabrepo>[#<commit-ish>]:
This command will install the package at https://gitlab.com/gitlabname/gitlabrepo by attempting to clone it using git. An example is shown below:
ALGORITHM
Npm uses the following algorithm to install a package:
The limitations of npm's install Algorithm
npm will always refuse to install any package with an identical name to the current package. You can overwrite this with the -force flag, however, in most cases you can address this by changing the name of the local package.
Npm install-ci-test
This command is used to install a project with a clean slate and run tests.
Synopsis
Description
This command is run as npm ci followed immediately followed by an npm test.
Npm install-test
This will install package(s) and run tests.
Synopsis
Description
This command will be run as npm install followed immediately by an npm test. It takes the same arguments as npm install.
Previous:
Mastering npm-hook and npm-init CLI Commands.
Next:
Mastering npm-link and npm-logout CLI Options.
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics