I’m trying to fetching json file format from url, But I want the function inside of a class, but I got an undefined thing on output, here’s all my codes:
const axios = require('axios');
var BASE_URL = 'https://estra-api.herokuapp.com/'
class loadData {
constructor() {
self.sfw = {};
self.nsfw = {};
}
getData(){
axios.get(BASE_URL)
.then(function data (response) {
return response.data["link"]
})
}
}
console.log(loadData.getData())
My Output errors was
console.log(loadData.getData())
^
TypeError: loadData.getData is not a function
at Object.<anonymous> (C:UsersStawaDesktopEstraMainAPIEstraJS-APIindex.js:20:22)
at Module._compile (internal/modules/cjs/loader.js:1085:14)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
at Module.load (internal/modules/cjs/loader.js:950:32)
at Function.Module._load (internal/modules/cjs/loader.js:790:12)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:76:12)
at internal/main/run_main_module.js:17:47
I have tried to use console.log(loadData.getData)
it just give me output undefined