npm CLI Quick-Start for Organizations

Dan MacTough
Social Tables Tech
Published in
2 min readFeb 24, 2016

At Social Tables, we have a number of private npm packages, and I needed to create a new user, grant that user read-only access to our private packages. The npm docs are great. Really great. Go there for details. But here are the key commands for this (probably common) series of steps.

Create a new team

$ npm team create <scope:team>

Grant team read-only access to all existing private packages

# Get a list of all private packages for your organization (scope)$ npm access ls-packages <scope></scope># Returns json :'(
# Let's use https://github.com/trentm/json to help
# Install: npm install -g json
$ npm access ls-packages <scope> | json -Ma key</scope># Returns list of package names. Noice.# Tying it all together
$ for PKG in $(npm access ls-packages <scope> | json -Ma key); do \
npm access grant read-only <scope:team> "${PKG}"; \
done

Create a new user

  • Backup your existing ~/.npmrc
$ npm adduser
  • Save your credentials (auth token will be in ~/.npmrc)
  • Restore your previous ~/.npmrc

Invite user to organization

Not implemented from the CLI. Use the website: https://www.npmjs.com/org/<scope>/members

Add user to a team

$ npm team add <scope:team> <user>

Remove user from a team

$ npm team rm <scope:team> <user>

Originally published at blog.mact.me on February 24, 2016.

--

--

Dan MacTough
Social Tables Tech

Husband, father, #nodejs developer, recovering law-talking guy