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.
question from:
https://stackoverflow.com/questions/65885835/node-function-calling-another-function-and-returns-undefined 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…