GithubHelp home page GithubHelp logo

npm-shell-login's Introduction

NPM Shell Login

Whenever you're using a CI service, or containers, you may face the problem of login to npm. The usually offered solution to do npm login -e | echo ... doesn't work on all shells. This package offers a reliable solution to perform npm login in any shell, from any script.


  • define environment variables for your credentials :
# replace ~/bash_profile with ~/.zshrc if you're using zsh
# fill in the <values below>

$ echo "export NPM_USER=<npm_username>" >> ~/.bash_profile
$ echo "export NPM_PASS=<npm_password>" >> ~/.bash_profile
$ echo "export NPM_EMAIL=<npm_email>" >> ~/.bash_profile
$ source ~/.bash_profile
  • make sure you have node ^8.11.3 and npm ^5.5.0
  • run $ npx npm-shell-login

If the command is successful, you are logged in to npm, and it will output the npm token created by the login process in your ~/.npmrc file should you need it somewhere else

You can also use this in another js script:

const { npmLogin, getNPMToken } = require("npm-shell-login");

// npmLogin returns a promise which resolves with the response code from
// the login process
// if it's 0, all went well, if not, the login failed
// it will only reject if the child process times out (20 seconds)
const code = await npmLogin();
if (code === 0) { /* yay ! */ }
else { /* oh no ! */ }

// getNPMToken will return a promise with the token from your ~/.npmrc file
const token = await getNPMToken();


PRs for bug fixes, enhancements and new features are welcome !

Simply clone the repo, and run yarn to install dependencies. You can run the script locally by running $ node index.js

npm-shell-login's People


francois-codes avatar


 avatar  avatar  avatar


 avatar  avatar



Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.