Comprehensive Guide to npm-ci, npm-completion, and npm-config Commands
In this tutorial we will examine the workings of the ci, completion and config cli options of npm.
npm-ci
The npm-ci command is used to install a project with a clean slate.
Synopsis
npm ci
example
Ensure that you have a package-lock and an install that is up to date:
$ cd ./my/npm/project
$ npm install
added 202 packages in 10s
$ ls | grep package-lock
Then, npm ci inside that project
`$ npm ci
added 201 packages in 5s
you should configure Travis to use npm ci to build instead of npm install:
# .travis.yml
install:
- npm ci
# keep the npm cache around so as to speed up installs
cache:
directories:
- "$HOME/.npm"
Description
The npm-ci command is similar to npm install, the only difference is that it is meant to be used in an automated environment such as test platforms, continuous integration, and deployment. The command can be significantly faster than a regular npm install by skipping certain user-oriented features. It is equally stricter than a regular install, this helps catch errors or inconsistencies that results from incrementally-installed local environment of most npm users.
Here are the main differences between using npm install and npm ci:
- The project should have an existing package-lock.json or npm-shrinkwrap.json.
- If dependencies in the package lock don't match those in package.json, npm ci exits with an error, rather than updating the package lock.
- npm ci will only be able to install entire projects at a time: individual dependencies will not be added with this command.
- In the case where a node_modules is already present, it is automatically removed before npm ci begins its install.
- Npm ci will never write to package.json or any of your package-locks: all installs are essentially frozen.
npm-completion
The npm-completion is a tab completion for npm.
Synopsis
source <(npm completion)
Description<
The npm-completion enables tab-completion in all npm commands.
The synopsis given above, will load the completions into your current shell. Adding it to your ~/.bashrc or ~/.zshrc makes the completions available everywhere:
npm completion >> ~/.bashrc
npm completion >> ~/.zshrc
it is also possible to pipe the output of npm completion to a file such as /usr/local/etc/bash_completion.d/npm if you have a system that reads that file for you.
When COMP_CWORD, COMP_LINE, and COMP_POINT are defined in the environment, npm completion will act in "plumbing mode" and will output completions based on the arguments.
npm-config
The npm-config is used to manage the npm configuration files.
Synopsis
npm config set [-g|--global]
npm config get <key>
npm config delete <key>
npm config list [-l] [--json]
npm config edit
npm get <key>
npm set <key> <value> [-g|--global]
aliases: c
Description
The config setting for npm is gotten from the command line, environment variables, npmrc files, and in some cases, the package.json file.
You can use the npm config command to update and edit the contents of the user and the global npmrc files.
Sub-commands
The npm-config supports the following sub-commands:
Set
This sub-command sets the config key to the value.
npm config set key value
If you omit this value, then it is set to true by default.
Get
npm config get key
The get sub-command will echo the config value to stdout.
List
npm config list
Shows all the config settings. You should use -l to also allow show defaults. Using the -json flag will show the setting in json format.
Delete
npm config delete key
This command will delete the keys from all configuration files.
Edit
npm config edit
This sub-command will open the coding file in an editor. You should use the -global flag to edit the global config.
Previous:
Comprehensive Guide to npm-build, npm-cache, and npm-bundle Commands.
Next:
Comprehensive Guide to npm-dedupe, npm-deprecate, and npm-dist-tag Commands.
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://www.w3resource.com/npm/ci-completion-and-config-cli-options.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics