Using npm login on CircleCI

When using npm to install a private module in a continuous integration environment for the first time, a brick wall is quickly hit. The npm login command is designed to be used interactively. This causes an issue in CI, scripts, etc. Here’s how to use npm login on CircleCI.

Step 1 - Private Environment Variables

For reusability, we can set npm login info in environment variables (envar). While we can set envars in circle.yml, this will appear in Git and thus be public. Instead, we can use private envars via or the API. The following variables should be set (variable names can be changed, just stay consistent):


Step 2 - The Actual Login Request

Various workarounds to get npm login working exists. Here is a fairly simple method that can be done in circle.yml:

    - echo -e "$NPM_USER\n$NPM_PASS\n$NPM_EMAIL" | npm login