Introduction to New Functions of npm profile

Posted by cinos11 on Thu, 09 May 2019 09:27:03 +0200

Reprinted address

Introduction to New Functions of npm profile

The new version of npm has a new function, npm profile, which can change your profile information. You can modify your profile without going to the website later.

Specific support for this function is probably in version 6. If your npm version does not have this command, it is recommended to upgrade and try it.

npm install -g npm

The main function of npm profiles is to change the settings of registry profile s. At first, I was very masked. I don't know when profile is, can't I just call user information directly? But when we log in through the address of the official website and click on the image on the right side, we will find a drop-down list with a "Profile Settings" in it, so I seem to understand. In fact, it is just to change their user information. You can go inside and see that the basic information is the same as the options we will list later for profile support.


An overview of npm profile is as follows

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


These are the main functions, which are almost the same as the screenshot above. If the corresponding options are added in the future, the corresponding configuration options should be updated as well.

The following details

Change your profile information in registry.
If you use non-npmjs registry, you cannot use this feature.

npm profile get [<property>]:

Show attributes in all profile s or one or more attributes, such as my attributes include the following

┌─────────────────┬──────────────────────────────────┐
│ name            │ durban                           │
├─────────────────┼──────────────────────────────────┤
│ email           │ zhangdapeng89@126.com (verified) │
├─────────────────┼──────────────────────────────────┤
│ two-factor auth │ disabled                         │
├─────────────────┼──────────────────────────────────┤
│ fullname        │ durban zhang                     │
├─────────────────┼──────────────────────────────────┤
│ homepage        │ www.gowhich.com                  │
├─────────────────┼──────────────────────────────────┤
│ freenode        │                                  │
├─────────────────┼──────────────────────────────────┤
│ twitter         │                                  │
├─────────────────┼──────────────────────────────────┤
│ github          │                                  │
├─────────────────┼──────────────────────────────────┤
│ created         │ 2015-03-18T02:35:58.918Z         │
├─────────────────┼──────────────────────────────────┤
│ updated         │ 2018-07-17T06:27:25.590Z         │
└─────────────────┴──────────────────────────────────┘


Here's a hint if you're running

npm profile

If there is no such thing as what I said above, there will be a problem that you haven't logged in and need to be executed.

npm login

Log in

npm profile set <property> <value>: 

Set the value of the property in the profile. The properties you can set include the following
email, fullname, homepage, freenode, twitter, github

npm profile set password: 

Change your password. This is an interactive function. You will be prompted to enter your current password and a new password. If double-factor authentication is enabled, you will also need to enter an OTP [dynamic password]

npm profile enable-2fa [auth-and-writes|auth-only]: 

Double-factor authentication is allowed, and the default mode is auth-and-writes.
There are several patterns

auth-only: OTP [dynamic password] is required when logging in or modifying account information. This OTP [dynamic password] will be required on both the Web site and the command line.
Auh-and-writes: OTP [dynamic password] is required at all times of auth-only, and an OTP [dynamic password] is also required when setting up the latest dist-tag in the publishing module or changing access rights through npm access and npm owner.

npm profile disable-2fa: 

Double-factor authentication is prohibited

All npm profile subcommands accept -- json and -- parseable and will adjust their output based on these commands.
Some of these commands may not be available in non-npmjs registry.

Topics: npm JSON github