I put this question up in order for easy access of the solution for fellow developers searching for an answer
//If you have an axios instance declared in a module similar to this, say, api.js
var axios = require('axios');
var axiosInstance = axios.create({
baseURL: '',
/* other custom settings */
});
module.exports = axiosInstance;
//If you are accessing the module somewhere else, like this
var api = require('./api');
api.get('relative/path') //For a typical get call using an instance
But, you want to find the baseURL for some business requirement from an axios instance and not necessarily make a call, how do you find it?
I put this question up in order for easy access of the solution for fellow developers searching for an answer
//If you have an axios instance declared in a module similar to this, say, api.js
var axios = require('axios');
var axiosInstance = axios.create({
baseURL: 'https://example./foo/bar',
/* other custom settings */
});
module.exports = axiosInstance;
//If you are accessing the module somewhere else, like this
var api = require('./api');
api.get('relative/path') //For a typical get call using an instance
But, you want to find the baseURL for some business requirement from an axios instance and not necessarily make a call, how do you find it?
Share Improve this question asked Jul 1, 2021 at 12:37 Susmita SilSusmita Sil 2132 silver badges9 bronze badges3 Answers
Reset to default 10https://github./axios/axios#global-axios-defaults
in your case should be : baseURL = api.defaults.baseURL
My Api js file
const instance = axios.create({ baseURL: "http://localhost:3157/api/v1", your base url headers: { "Content-type": "application/json", }, });
export default instance;
import instance from 'api.js';
let baseURL = instance.dafaults.baseURL;
var axiosInstance = axios.create({
baseURL: 'https://example./foo/bar',
/* other custom settings */
});
//Use this --> "axiosInstance.getUri()"
console.log(axiosInstance.getUri());
<script src="https://cdn.jsdelivr/npm/axios/dist/axios.min.js"></script>