E
E
eeeboy2021-08-20 09:51:38
Node.js
eeeboy, 2021-08-20 09:51:38

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;


index.js
let   hde        = require("./hdeconnect.js");
console.log("с приложения кол-во тикетов " + hde()) //возвращает undefined


Please point me to my mistake, if any :)

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question