title: How to access database with username and password in Axios
body: <p>I'm just a beginner with axios and javascript and would appreciate your help.</p>
  <p>I have a database called <code>mydb</code> in MongoDb. To access this database, it is necessary to use the username <code>root</code> and password <code>example</code>.</p>
  <p>Then I have a basic web app that allows registering new users in the database <code>mydb</code>. How can I update my <code>axios</code> script to access the database with the username <code>root</code> and password <code>example</code>.</p>
  <p>This is my code:</p>
  <pre><code>const handleRegister = () =&gt; {
      if (username &amp;&amp; password) {
          const formData = new FormData();
          formData.append('username', username);
          formData.append('password', password);
          axios.post(config.api.url + '/auth/register', formData)
              .then(res =&gt; {
                  console.log(res)
              })
              .catch(err =&gt; {
                  console.log(err)
              })
      }
  }
  </code></pre>
  <p><strong>UPDATE:</strong></p>
  <p>I have a backend with <code>db.js</code> script:</p>
  <pre><code>const mongoose = require(&quot;mongoose&quot;);
  
  const dbURI = &quot;mongodb://root:example@mongo:27017/mydb?readPreference=primary&amp;appname=MongoDB%20Compass%20Community&amp;ssl=false&quot;;
  
  const options = {
      useNewUrlParser: true,
      useUnifiedTopology: true,
      useFindAndModify: false
  };
  
  // Connects the database to the server
  mongoose.connect(dbURI, options).then(
      () =&gt; {
          console.log(&quot;Database connection established!&quot;);
      },
      err =&gt; {
          console.log(&quot;Error connecting Database instance due to: &quot;, err);
      }
  );
  </code></pre>