简体   繁体   中英

How to use "#" in dotenv as value | nodejs

I have logins and passwords. As sample LOGINS="sample1@mail.com","sample2@mail.com" and PASSWORDS="qwer123,@#","rewq4321$#@!"

Passwords contain a "#" . And.env remove all after this symbol. If i try to console.log result is just "qwer123!@" without a second pass and "#"

I tried to use "\" but it`s do nothing

I expect to use my passwords array with special charcters

Try this way, Put all passwords in single string separated by , and then split them so it would give an array.

// .env
PASSWORDS="qwer123!@#,rewq4321$#@!"

and call the env value like this

const passwords = process.env.PASSWORDS?.split(',');
// Output: [ 'qwer123!@#asda', 'rewq4321$#@!' ]

Metadata: I've used dotenv package in order to access the env variables from process.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM