w3resource

Mastering npm-pack, npm-ping, and npm-prefix Commands for Efficient Package Management


In the previous tutorial we examined how the npm-outdated and npm-owner cli commands work, in this tutorial we will look at how the npm-pack, npm-ping and npm-prefix cli options work.

Npm-pack

The npm-pack command creates a tarball from a package.

Synopsis

npm pack [[<@scope>/]<pkg>...]

Description

For anything that is installable (this includes a package folder, a tarball, a tarball url, a name@tag, a name@version, name or a scoped name), this command fetches it to the cache, and then it copies the tarball to the current working directory as <nam>-<version>.tgz, and then it will write the filenames out to the stdout.

In the case where the you specify the same package multiple times, the file will be overwritten the second time.

If you do not supply any argument, then npm will pack the current folder.

Npm-ping

The npm-ping will ping the npm registry.

Synopsis

npm ping [--registry <registry>]

Description

This command will ping the configured or given npm registry, as well as verify authentication. If the command works it outputs something that looks like this:

Ping success: {*Details about registry*}

Else it will output:

Ping error: {*Detail about error}

npm-prefix

This command will display the prefix.

Synopsis

npm prefix [-g]

Description

The npm prefix command will print the local prefix to standard out. This is the closest parent directory that contains a pakage.json unless you specify a -g flag.

The prefix will be the the value of the global prefix if the -g flag is specified.

npm-profile

This is used to change settings on your registry profile.

Synopsis

npm profile get [--json|--parseable] [<property>]
npm profile set [--json|--parseable] <property> <value>
npm profile set password
npm profile enable-2fa [auth-and-writes|auth-only]
npm profile disable-2fa

Description

This is used to change profile information on the registry. This command is not available if you are using a non-npmjs registry.

  • npm profile get [<property>]: Displays all of the properties of your profile, or one or more specific properties. It will look like:
`+-----------------+---------------------------+
| name            | example                   |
+-----------------+---------------------------+
| email           | [email protected] (verified) |
+-----------------+---------------------------+
| two factor auth | auth-and-writes           |
+-----------------+---------------------------+
| fullname        | Example User              |
+-----------------+---------------------------+
| homepage        |                           |
+-----------------+---------------------------+
| freenode        |                           |
+-----------------+---------------------------+
| twitter         |                           |
+-----------------+---------------------------+
| github          |                           |
+-----------------+---------------------------+
| created         | 2015-02-26T01:38:35.892Z  |
+-----------------+---------------------------+
| updated         | 2017-10-02T21:29:45.922Z  |
+-----------------+---------------------------+
  • npm profile set <property> <value>: Sets the value of a profile property. You can set the following properties like this: email, fullname, homepage, freenode, twitter, github
  • npm profile set password: Changes your password. This option is interactive, you will be prompted for your current password and a new password. You will also be prompted for an OTP if you have two-factor authentication enabled.
  • npm profile enable-2fa [auth-and-writes|auth-only]: This will enable two-factor authentication. It will default to auth-and-writes mode. Modes are:
  • auth-only: This requires an OTP when logging in or making changes to your account's authentication. The OTP is required on both the website and the command line.
  • auth-and-writes: This requires an OTP at all the times auth-only does, and also requires one when you are publishing a module, sets the latest dist-tag, or changing access using npm access and npm owner.
  • npm profiledisable-2fa: This will disable two-factor authentication

DETAILS

All npm profile commands accept -json and -parseable, they will also tailor their output based on those. Some of the commands may not be available on non npmjs.com registries.

Previous: Efficient Package Management with npm-outdated and npm-owner Commands.
Next: How to Use npm-prune and npm-publish Commands Effectively.



Become a Patron!

Follow us on Facebook and Twitter for latest update.

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-pack-npm-ping-npm-prefix-and-npm-profile-cli-commands.php