Answer the question
In order to leave comments, you need to log in
Is the behavior of module.exports normal?
When requesting the server directly in the function, I get the correct response, but when I try to call this function from another file, I get undefined.
Code: hdeconnect.js
const config = require('./config.json');
const fetch = require('node-fetch');
const api_key = Buffer.from(config.HDE_TOKEN).toString('base64');
const domain = 'https://helpdeskeddy.com/api/v2/'
function getTickets() {
let url = `${domain}tickets/?status_list=open`;
fetch(url, {
method: 'GET',
headers: {
'Authorization': 'Basic ' + api_key
}
}).then(response => response.json())
.then( result => {
console.log("c модуля количество тикетов " + result.pagination.total) // возвращает значение
return result.pagination.total
})
}
module.exports = getTickets;
let hde = require("./hdeconnect.js");
console.log("с приложения кол-во тикетов " + hde()) //возвращает undefined
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question