Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to change npm user? [closed]

Editing profile is easy and intuitive but there seem to be username change feature missing. I am trying to find a way to change my npm username from npmjs.com.

The only thing I come up with so far is to register new user, add it to all packages and make it an owner of them.

Is there a way I can simply change my npm user?

like image 608
FullStackForger Avatar asked Sep 30 '16 17:09

FullStackForger


People also ask

How do I reset my npm credentials?

npm config edit Opens the config file in an editor. Use the --global flag to edit the global config. now you can delete what ever the registry's you don't want and save file. npm config list will display the list of available now.

How do I delete npm account?

From the web, you can delete your npm user account. Log in to npm with your user account. In the upper right corner of the page, click your profile picture, then click Account. On this page, you will find a button to delete your account.

How do I find my npm username?

Description. Display the npm username of the currently logged-in user. If logged into a registry that provides token-based authentication, then connect to the /-/whoami registry endpoint to find the username associated with the token, and print to standard output.


1 Answers

The npm support told me to create a new account and move packages manually. Not great.

So here's a way to move your existing packages to your new account:

  1. Log into your old account on both https://www.npmjs.com and on your bash/zsh terminal
  2. Get a list of your current npm packages:

    1. Go to your profile on npmjs.com
    2. Expand the whole list until there's no more "show more packages" button
    3. Run this in your browser's console, it will copy the package names to the clipboard:

      copy($$('[href^="/package/"]').map(a => a.textContent).join(' '))
      
  3. Save the list in a variable in your terminal:

    1. Type PACKAGES="
    2. Paste what the space-delimited list of packages you copied earlier
    3. Type " and press enter
  4. Add the new user as an owner

    1. Replace NEW with your new user’s name, and run this, it will show a preview:

      for PKG in $PACKAGES; do echo npm owner add NEW $PKG; done
      
    2. Run the same command you just run, but remove echo. This can take a couple of seconds for each package you have. Some packages might require an OTP if you use 2FA

🎉 Congratulations! You just added your new account as owner of your packages.

Now you can either delete your old npm account, or run that last command again replacing add NEW with remove OLD, where OLD is your old username.

like image 138
fregante Avatar answered Oct 05 '22 18:10

fregante