如何return回调node.js?

How to return callback node.js?

var iwconfig = require("wireless-tools/iwconfig");
let api = {};

api.getStatusWifi = function () {
  iwconfig.status(function (err, status) {
    console.log(status);
  });
  // return status ???????????
};

module.exports = api;

如何将“状态回调”return 传递给“getStatusWifi”?

您需要将“api.getStatusWifi =”部分放在状态变量可用的函数中。

var iwconfig = require("wireless-tools/iwconfig");
let api = {};

 iwconfig.status(function (err, status) {
    api.getStatusWifi = function () {
     return status;
    };
 });
  
module.exports = api;