Skip to content

Instantly share code, notes, and snippets.

@manifestinteractive
Created September 2, 2017 03:41
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save manifestinteractive/2ce45898fbf43dba4e20e3885c26d212 to your computer and use it in GitHub Desktop.
Save manifestinteractive/2ce45898fbf43dba4e20e3885c26d212 to your computer and use it in GitHub Desktop.
Multiple NPM Accounts on Single Machine

Multiple NPM Accounts on Single Machine

Create Custom NPM Config

If you do not already have a local ~/.npmrc file, you need to create one.

  1. Open a terminal window
  2. Run npm login
  3. Login Info for one account

Rename Custom NPM Config

Once you have a ~/.npmrc file, we'll need to change it's name.

  1. Before renaming your config file, customize any additional settings you might want
  2. Rename ~/.npmrc to indicate the account via mv ~/.npmrc ~/.npmrc-project

Alias Custom NPM

For each account you want to create, we'll need to create an npm alias to use.

  1. Edit your bash profile, e.g. ~./zshrc or ~/.profile, let's assume ~./zshrc via nano ~./zshrc
  2. Add a custom alias to the end of the file alias npm-project='npm --userconfig ~/.npmrc-project'
  3. Update your open terminal window with new alias source ~./zshrc

Using Custom NPM

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 install

You 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]

Notes

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment