Node.js newbie here. I'm writing a monitoring node in node-red and wanted to use the "node-df" package to get some data of disk usage. I'm using the function call as the code below and wanted to store the response in a variable outside the function scope. However, the response does not get stored in the df_str variable as I wanted to.
node-df link: https://www.npmjs.com/package/node-df
var df = require('node-df');
function monitor_json(node, msg) {
var df_str = "";
df(function (error, response) {
if (error) { throw error; }
node.warn(response);
df_str = response;
node.warn(df_str);
});
node.warn(df_str);
}
Where the "node.warn()" function call logs output in the console.
The node.warn() inside the df function logs the expected result string to the console, while the last node.warn() logs " " in the console. How can I set the df_str variable inside the nested function?