Give credentials to npm login command line
I found a npm package for this some months ago but I forgot to update this question.
Just install npm-cli-login and in the terminal/scripts use it as below:
npm-cli-login -u testUser -p testPass -e test@example.com
I found two other ways to pass the credentials without the need to use an external command BUT be aware that these commands might NOT work in environments such as Jenkins.
Commands:
# First wayecho -e 'USERNAME\nPASSWORD\nEMAIL' | npm login -e EMAIL -r REGISTRY# Second waynpm login -e EMAIL -r REGISTRY << EOFUSERNAMEPASSWORDEMAILEOF
Take a look at the .npmrc
file you can use this file to set npm configuration variables, such as credentials, registry location, etc... This file is located in your HOME directory. Here is an example .npmrc
file to use for reference:
~/.npmrc
registry=https://registry.npmjs.com/_auth="<token>"email=<email>always-auth=true
substitute your email and _auth token appropriately for your credentials. Your script will use these global configurations set within your .npmrc
file.
Hopefully that helps!
Typing npm login
from the command line and entering your credentials will automatically generate an npm token and setup your .npmrc file for you.