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.
Npm-view
The npm-view will help you view information about a registry.
Synopsis
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
Description
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[0].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
OUTPUT
If only a single string field for a single version is the output, then it won't be colorized or quoted, this is to enable piping of the output to another command. In the case where the field is an object, it is output as a JavaScript object literal.
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.
Npm-whoami
This command displays the username contained in a registry.
Synopsis
npm whoami [--registry <registry>]
Description
Prints the username config to the standard output.
Previous:
Npm-update and npm-version cli commands
Next:
Npm-folders
- New Content published on w3resource :
- 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
- Angular - JavaScript Framework
- React - JavaScript Library
- Vue - JavaScript Framework
- Jest - JavaScript Testing Framework