title: How to set Authorization token with axios in node.js
body: <p>I want to use axios in api test. To initialize client I need first to set auth token, which I expect to get with axios as well.How to get it form async code? </p>
  
  <pre><code>const a = require('axios');
  
    getToken = () =&gt; {
      var axios =a.create({
          baseURL: 'http://local.v2.app.com/api/auth/v1.0',
          headers: {'Content-Type': 'application/json'},
        });
  
        return axios.post('/credentials/login', {
          username: '1@test.com',
          password: 'Test@1234'
        })
        .then(function (response) {
          return response.data.data.token;
        })
        .catch(function (error) {
          console.log(error);
        });
  
    }
  
    const client=a.create({
      baseURL: 'http://local.v2.app.com/api/auth/v1.0',
      headers: {
          'Content-Type': 'application/json',
          'Authorization':  getToken()
  },
    });
  
    module.exports = client; 
  </code></pre>