I want to automate the npm login process via a bash script.
I tried it with this snippet:
/usr/bin/expect -f - <
using with npm-cli-login package it worked
# npm install -g npm-cli-login
# npm-cli-login -u myUser -p myPass -e t@ex.com -r http://192.168.56.1:4873
Checking if it is installed or not:
# whereis npm-cli-login
npm-cli-login:
# whereis npm-cli-login | grep '/npm-cli-login' -ic
0
After installation:
# npm install -g npm-cli-login
Check if it is installed:
# whereis npm-cli-login
npm-cli-login: /usr/bin/npm-cli-login
# whereis npm-cli-login | grep '/npm-cli-login' -ic
1
Let's login:
# npm-cli-login -u myUser -p myPass -e t@ex.com -r http://192.168.56.1:4873
info attempt registry request try #1 at 10:13:19 PM
http request PUT http://192.168.56.1:4873/-/user/org.couchdb.user:myUser
http 409 http://192.168.56.1:4873/-/user/org.couchdb.user:myUser
info attempt registry request try #1 at 10:13:19 PM
http request GET http://192.168.56.1:4873/-/user/org.couchdb.user:myUser?write=true
http 200 http://192.168.56.1:4873/-/user/org.couchdb.user:myUser?write=true
info attempt registry request try #1 at 10:13:20 PM
http request PUT http://192.168.56.1:4873/-/user/org.couchdb.user:myUser/-rev/undefined
http 201 http://192.168.56.1:4873/-/user/org.couchdb.user:myUser/-rev/undefined
#
# npm whoami
myUser
#
# npm logout
# npm whoami
npm ERR! code ENEEDAUTH
npm ERR! need auth This command requires you to be logged in.
npm ERR! need auth You need to authorize this machine using `npm adduser`
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2020-04-21T22_13_42_373Z-debug.log