I am very new to nodejs. I have been playing around trying to implement a npm package node-cmd, execute the cmd and set the output equal to a variable. I have implemented the following:
var cmd=require('node-cmd');
var dir;
function test(data)
{
console.log("data content: " + data)
};
var outputStuff = cmd.get('pwd',test);
console.log("outputStuff content: " + outputStuff);
output:
outputStuff content: undefined'
data content: /Users/jduff/Development/node/systemProperties
It is clear that the var "outputStuff" is set prior to executing the cmd.get function and returns 'undefined'. So my recollection from the course I took a while ago is that the outputStuff variable is being hoisted and set prior to executing the function. My question is how would I get the contents of the function to be set to the variable outputStuff.
console.log(outputStuff)
output:
outputStuff content: /Users/jduff/Development/node/systemProperties
Any insights to what I am missing will be greatly appreciated.