Comprehensive Guide to npm-search and npm-shrinkwrap Commands
There are certain times where you don't the exact name of the package you want; in such cases you can use the npm-search command to search for the package, this will help you eliminate the error of installing wrong package.
There are also times when you want to lock down dependency versions for publication, for this npm provides the npm shrinkwrap cli option.
This tutorial will work you though both cli options.
Npm-search
The npm-search is used to search for packages.
Synopsis
npm search [-l|--long] [--json] [--parseable] [--no-description] [search terms ...]
aliases: s, se, find
Description
The npm-search will search for the packages that matches your search terms. The search performed by npm search is a linear, incremental, lexically-ordered search through package metadata for files in the npm registry. If you have color enabled. It will highlight the matches in the results.
In addition, when you use the -searchopts and -searchexclude, options that paired with more search terms will include and exclude further patterns respectively. The main difference between the standard search terms and -searchopts is that -searchopts does not highlight results in the output and can be used when we need more fine-grained filtering. Additionally, you can add both the -searchopts and -searchexclude to the .npmrc for default search filtering behavior.
Search equally enables you to target maintainers in search results, this is done by prefixing their npm username with =.
Whenever a term starts with /, it is interpreted as a regular expression and will support standard JavaScript RegExp syntax. A trailing / is ignored in this case. (it should be noted that many regular expression characters have to be escaped or quoted in most shells)
Configuration
description
When used as -no-description, it disables search matching in package descriptions and suppresses the displays of that field in the results.
- Default: true
- Type: Boolean
json
The json config option outputs search results as a JSON array.
- Default:false
- Type: Boolean
long
This displays a full package description and other long text across multiple lines. When it is disabled (which is the default) search results will be truncated to fit neatly on a single line. Modules that have extremely long names will fall on multiple lines.
- Default: false
- Type: Boolean
searchopts
- Default: ""
- Type: String
These are space-separated options that are always passed to search.
searchexclude
- Default: ""
- Type: String
These are space-separated options that limit the results from search.
searchstaleness
- Default: 900 (15 minutes)
- Type: Number
This is the age of the cache, in seconds, before another registry request is made.
registry
- Default: https://registry.npmjs.org/
- Type: url
Searches the specified registry for modules. If you configured npm to point to a different default registry, like your internal private module repository, npm search defaults to that registry when searching. You should pass a different registry url such as the default above in order to override this setting.
Npm-shrinkwrap
The npm shrinkwrap helps you to lock down dependency versions for publication.
Synopsis
npm shrinkwrap
Description
This command will repurpose package-lock.json into a publishable npm-shrinkwrap.json or it will simply create a new one. The file that is created and updated by this command then takes precedence over any other existing or future package-lock.json files.
Previous:
Comprehensive Guide to npm Rebuild, Repo, Restart, Root, and Run-Script Commands.
Next:
Guide to npm-star, stars, start, and stop 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://w3resource.com/npm/npm-search-and-npm-shrinkwrap-cli-commands.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics