The last time Hackerfall tried to access this page, it returned a not found error. A cached version of the page is below, or click here to continue anyway

GitHub - nifty-archive/npm-as: Run npm as a certain user.


Run npm as a certain user.

What? Why?

npm-as is a solution to a problem we have been having. npm, Inc does not offer teams for open source projects. Scoped packages only work for teams and regular users. Because we're using scoped packages for open source projects, our only two options are to pay for private packages even though we don't need them to use teams, or we use user accounts as a makeshift team.

We chose option 2. One of the biggest issues with this route is that to create a package and publish it, you have to npm login as that user, publish the package, then add all the owners you want to have access to it for them to publish. The workflow for this usually comes out to the following steps.

~/projects/cool-package $ npm login
Username: example
Password: hunter2
Email: (this IS public)

~/projects/cool-package $ npm publish --access public

~/projects/cool-package $ npm owner add rad-maintainer

~/projects/cool-package $ npm login
Username: rad-maintainer
Password: hunter2
Email: (this IS public)

For every package you publish. This is very cumbersome and time consuming to do.

In steps npm-as. This package is a simple passthru package that adds a simple token management system and --as flag to npm commands.


$ npm install -g @niftyco/npm-as


To use npm-as You can either use it as is by issuing all commands to npm-as instead of npm. Or you can alias it to npm.

After that you need to edit your $HOME/.npmrc file to use an environment variable over a token in the registry url.

Look for the line that looks something like this // and replace it all with //${NPM_TOKEN}.

npm-as uses the NPM_TOKEN environment variable to swap your tokens when you issue an --as flag.

$ export alias npm="npm-as"

$ npm whoami

$ npm whoami --as example

You can add users by using the tokens sub command:

$ npm tokens add steve afe246n-345adf-adsf235
you can now `--as steve`

NOTE: You need to have logged in under this account with npm cli at least once to generate the token. You can access all your tokens on npm. If you have aliased npm to npm-as You will need to remove the alias temporarily and login, then redo the setup steps.

Continue reading on