If you do not already have a local ~/.npmrc file, you need to create one.
- Open a terminal window
- Run
npm login - Login Info for one account
Once you have a ~/.npmrc file, we'll need to change it's name.
- Before renaming your config file, customize any additional settings you might want
- Rename
~/.npmrcto indicate the account viamv ~/.npmrc ~/.npmrc-project
For each account you want to create, we'll need to create an npm alias to use.
- Edit your bash profile, e.g.
~./zshrcor~/.profile, let's assume~./zshrcvianano ~./zshrc - Add a custom alias to the end of the file
alias npm-project='npm --userconfig ~/.npmrc-project' - Update your open terminal window with new alias
source ~./zshrc
Now that we have a customized npm setup we just simply need to use npm-project rather than npm when we want to use customozid NPM settings.
Examples:
npm-project installYou can also continue to customize NPM's config to update your custom config file too:
npm-project config set <key> <value> [-g|--global]
npm-project config get <key>
npm-project config delete <key>
npm-project config list [-l]
npm-project config edit
npm-project get <key>
npm-project set <key> <value> [-g|--global]This example uses npm-project and .npmrc-project as names, but you obviously can use any other word
besides project. You can also make as many of these npm aliases and configuration files as you want
which is super handy if you are on a few different teams that require different npm user accounts.