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?
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.
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.
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.
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:
Get a list of your current npm packages:
npmjs.com
Run this in your browser's console, it will copy the package names to the clipboard:
copy($$('[href^="/package/"]').map(a => a.textContent).join(' '))
Save the list in a variable in your terminal:
PACKAGES="
"
and press enter
Add the new user as an owner
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With