I have a javascript file "populationTest.js" which calls a second javascript file "populationReaderTest.js". The first one handles allocating the extracted data where it needs to go and the second filters through the filesystem to find the correct files and grabs the data. I can find the file, read the data and print it to the console but I do not know how return the data back to where it is called. Any tips on how I can achieve this?
Code snipit from "populationTest.js"
import {main as popread} from "./populationtReaderTest.js"
...
...
var data = popread("./js/actionsFile.txt");
console.log(data);// prints undefined
console.log(typeof(data));// prints undefined
Code snipit from "populationReaderTest.js"
var globe;
var main = function(){
let path = "./js/actionsFile.txt" //path of the data to be extracted
d3.text(path,function(data){
console.log(data) //successfully prints the extracted data to console
globe = data;// doesn't work from here on
return globe;
});
console.log(globe)
return globe;
};
export { main };
I am only using the global variables and console.log() for debugging and testing purposes final iteration will preferably not use global variables and will not log to console.