0

I am trying to get the cpu serial number for the authentication. I use serial-number package to get the serial number but I cannot store the serial in other variable.

import * as serialNumber from 'serial-number';
var num = null;
serialNumber(function (err, value) {
 num = value;
 console.log(value);
});

console.log(num);
marco
  • 31
  • 10
  • 1
    The call is asynchronous. You have to put your whole code inside the function. That's how asynchronous coding works. – freakish Mar 30 '19 at 06:59
  • adding to answer above, `console.log(num)` is executed even before the callback `function (err, value)...` – 1565986223 Mar 30 '19 at 07:08
  • 1
    Possible duplicate of [How do I return the response from an asynchronous call?](https://stackoverflow.com/questions/14220321/how-do-i-return-the-response-from-an-asynchronous-call) – Evert Mar 30 '19 at 07:09
  • Possible duplicate of [How to return value from an asynchronous callback function?](https://stackoverflow.com/questions/6847697/how-to-return-value-from-an-asynchronous-callback-function) – 1565986223 Mar 30 '19 at 07:09

0 Answers0