QuickBlox JS in Node Environment

63 Views Asked by At

I am using QuickBlox in a node environment, which does not have XMLHttpRequest by default, so I get the following error:

Uncaught (in promise) ReferenceError: XMLHttpRequest is not defined
    at i (quickblox.min.js:2380:1)

Also installing xhr2 does not help.

Is there way to make QuickBlox work for node?

1

There are 1 best solutions below

1
Mr.Developer On

Use alternative npm for make http calls

Here, "axios" npm.

The axios package is also universal and can be used on the browser and on the server.

First, install the module:

npm install axios

Now you are able to use it:

import axios from 'axios';

async function getUser() {
  try {
    const response = await axios.get('https://randomuser.me/api/');

    return response.data;
  } catch (err) {
    console.log(err);
  }
}

console.log(await getUser());