Npm-view and npm whoami
This tutorial concludes the series on npm's cli command. In the previous tutorial we showed you how to npm-version as well as the npm update commands.
This tutorial will cover how you can view the info of a registry as well as the display your npm username.
The npm-view will help you view information about a registry.
So how do we go about this? The general syntax for running npm-view is as shown below.
npm view [<@scope>/]<name>[@<version>] [<field>[.<subfield>]...] aliases: info, show, v
The npm view command shows the data about a package and prints it to the stream that is referenced by the outfd config, which is stdout by default.
If you want to show the package registry for the vue package, you can do something like this:
npm view vue
The default version will be "latest" if it is not specified.
You can specify field names after the package descriptor. For instance, if you want to show the dependencies of the vue-scroll package at version 2.6.5, you can do this:
npm view [email protected] dependencies
You can also view child fields by separating them using a dot. For instance, if you want to view the git repository for the latest create-react-app version. You can do this:
npm view create-react-app repository.url and it will yield: git+https://github.com/facebook/create-react-app.git
This will make it easy to view information about a dependency with a bit of shell scripting. For instance, if you want to view all the data about the version of opts that vue-calendar depends on, you can do this:
npm view [email protected]$(npm view vue-calendar dependencies.opts)
For fields that are arrays, requesting a non-numeric field returns all of the values from the objects in the list. For instance, if you want to get all the contributor names for the "express" project, you can do this:
npm view express contributors.email
You can also use numeric indices in square braces to specifically select an item in an array field. To get the email address of the first contributor in the list alone, you can do this:
npm view express contributors.email
Multiple fields can be specified, and they will be printed one after another. For instance, if you want to get all the contributor names and email addresses, you may do this:
npm view express contributors.name contributors.email
"Person" fields will be shown as a string if they would be shown as an object. So, for example, this shows the list of npm contributors in the shortened string format
npm view npm contributors
If you provide a version range, then data is printed for every matching version of the package. This shows which version of jsdom was required by each matching version of yui3:
npm view [email protected]'>0.5.4' dependencies.jsdom
If you want to show the connect package version history, you can do this:
npm view connect versions
If you give the --json flag, the outputted fields will be given in JSON.
In the case where the version range matches multiple versions, then each printed value is prefixed with the version it applies to.
If you request multiple fields, then each of them will be prefixed with the field name.
This command displays the username contained in a registry.
npm whoami [--registry <registry>]
Prints the username config to the standard output.
- New Content published on w3resource:
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework