Search code examples
node.jsdotenv

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


I have logins and passwords. As sample LOGINS="[email protected]","[email protected]" 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


Solution

  • 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.