title: Storing a password in an environment variable using Node.js
body: <p>I am creating administrator credentials for my application. The model is quite simple; it has username and password properties and some validation as well. I have a function where I populate some information in the database.</p>
  <pre><code>async function init() {
    const admin = new Admin({
      username: &quot;admin&quot;,
      password: &quot;12345&quot;
    });
  
    const salt = await bcrypt.genSalt(10);
    admin.password = await bcrypt.hash(admin.password, salt);
  
    try {
      await admin.save({ username: admin.username });
    } catch (ex) {
      console.log(ex.message);
    }
  }
  </code></pre>
  <p>However, with this approach I am saving the password in my source code, and I don't want that. I was thinking that maybe I could store my administrator password in an environment variable using the <code>config</code> package.</p>
  <p>I tried the following:</p>
  <ul>
  <li><p>Created a <em>default.json</em> file:</p>
  <p><code>{ &quot;adminPassword&quot;: &quot;&quot; }</code></p>
  </li>
  <li><p>Created a <em>custom-environment-variables.json</em> file:</p>
  <p><code>{ &quot;adminPassword&quot;: &quot;fifteen_adminPassword&quot; }</code></p>
  </li>
  <li><p>Then I modified the code to this:</p>
  </li>
  </ul>
  <p><code>const admin = new Admin({ username: &quot;admin&quot;, password: config.get(&quot;adminPassword&quot;) });</code></p>
  <p>Finally I set the environment variable <code>export fifteen_adminPassword=12345</code>, but this fails as invalid password when I'm authenticating.</p>