Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 242
METALHEAD Avatar asked Aug 25 '18 13:08

METALHEAD


1 Answers

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);})
like image 173
Chris Cousins Avatar answered Oct 05 '22 11:10

Chris Cousins