I'm getting a reference error saying check is not defined when I call check().then(function(employees) towards the bottom of my code and I;m not sure why. This happens when I call getAllEmployees();
var employees = []; var departments = []; var error = 0; function initialize(){ var fs = require("fs"); fs.readFile("./data/employees.json", 'utf8', function(err, data){ if(err){ error = 1; } employees = JSON.parse(data); //console.log(employees); }); fs.readFile("./data/department.json", 'utf8', function(err, data){ if(err){ error = 1; } departments = JSON.parse(data); // console.log(departments); }); let check = function(){ return new promise(function(resolve,reject){ if (error === 0){ resolve("Success"); } else if(error === 1){ reject("unable to read file"); } }) }; } function getAllEmployees(){ check().then(function(employees){ console.log(employees); }).catch(function(){ console.log("No results returned"); }); }