NODEJS - AXIOS : Error : The “url” argument must be of type string. Received type object at Url.parse
NODEJS - AXIOS : Error : The “url” argument must be of type string. Received type object at Url.parse
I am trying to fetch data from a rest API using AXIOS as below:
require('dotenv').config();
const axios = require('axios');
var url = 'https://931eb067-05c0-492a-8129-48ebfc27d426-bluemix.cloudant.com/dummy/_design/NEW_VIEW_DESIGN/_view/new-view?include_docs=true';
axios.get(url,auth:
username: process.env.account,
password: process.env.password
).then((res)=>console.log(res.data);)
.catch((e)=>console.log(e));
I am able to access the metioned URL seperately by providing the credentials but I am getting the below error while using AXIOS
The "url" argument must be of type string. Received type object at Url.parse
What has gone wrong?
2 Answers
2
axios.get(url,auth:
username: process.env.account,
password: process.env.password
).then((res)=>console.log(res.data);)
Should be
axios.get(url,auth:
username: process.env.account,
password: process.env.password
).then((res)=>console.log(res.data);)
You putted url
inside the config confie parameter but it must be before the config.
url
axios.get(url, auth:
username: process.env.account,
password: process.env.password
).then((res)=>console.log(res.data);)
.catch((e)=>console.log(e));
Thank you for pointing out the mistake.
– METALHEAD
Aug 25 at 13:55
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
You saved the day man.... Thank you so much.
– METALHEAD
Aug 25 at 13:55