I want to automate the npm login process via a bash script.
I tried it with this snippet:
/usr/bin/expect -f - <<EOD spawn npm adduser expect "Username:" send "myUserName\n" expect "mail: (this IS public)" send "[email protected]\n" EOD   But without luck.
Note: I will change the strings with env variables
@Aurélien Thieriot: thanks for the hint.
I have two solutions for my problem:
export NPM_AUTH_TOKEN=myToken export NPM_EMAIL=myEmail   create/override ~/.npmrc by following shell script:
echo "_auth = $NPM_AUTH_TOKEN" > ~/.npmrc echo "email = $NPM_EMAIL" >> ~/.npmrc   export NPM_USERNAME=myUsername export NPM_PASSWORD=myPassword export NPM_EMAIL=myEmail   I know the order of the questions. So I can do the following:
npm adduser <<! $NPM_USERNAME $NPM_PASSWORD $NPM_EMAIL !   Note: solution 2 works only when the user isn't added yet
 Otherwise the $NPM_PASSWORD is not necessary
This way works and with a more elegant expect:
/usr/bin/expect <<EOD spawn npm adduser expect {   "Username:" {send "$USERNAME\r"; exp_continue}   "Password:" {send "$PASSWORD\r"; exp_continue}   "Email: (this IS public)" {send "$EMAIL\r"; exp_continue} } EOD 
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With