Home > Mobile >  axios get response is junk
axios get response is junk

Time:07-20

I am using axios to fetch some data from typicode api. The result I am getting is some junk like this.

enter image description here

// apis.js

const axios = require('axios');

const getRequest = async () => {
    const res = await axios.get('https://jsonplaceholder.typicode.com/posts/1');
    console.log(res.data);
}
getRequest();

I am running this code using command node apis.

I am expecting result as below, as shown mentioned at https://jsonplaceholder.typicode.com/posts/1

{
  "userId": 1,
  "id": 1,
  "title": "sunt aut facere repellat provident occaecati excepturi optio reprehenderit",
  "body": "quia et suscipit\nsuscipit recusandae consequuntur expedita et cum\nreprehenderit molestiae ut ut quas totam\nnostrum rerum est autem sunt rem eveniet architecto"
}

CodePudding user response:

The code is completely fine and works on my machine. This must be a problem with your environment. Are you inside a VPN of a company or make this call from a server that sits in a special network or anything like that?

  • Related