i have the following code in nodejs:
const unifi = require('node-unifi');
const controller = new unifi.Controller(IP_ADDRESS, 8443);
function login(apiCall) {
  controller.login(USERNAME, PASSWORD, function (err) {
    if (err) {
      console.log('ERROR: ' + err);
      return;
    }
    apiCall();
  });
}
function getAllClients(site) {
  login(function () {
    controller.getClientDevices(site, (res, data) => {
      console.log(data);
    });
  });
}
getAllClients('siteid');
In original call, any function needs to be called within login() so it can only be called while logged in. When i call the function getAllCients(siteID) i get desired result in console.log. But for love of god I can't get the result returned from the function in another file where I required the said function. Always get undefined.
I assume I need to use a callback but after reading multiple forums (i.e. art of node) I am no wiser were to have the callback.
Any help would be appreciated.
