So here is the module:
module.exports = function(word) {
fb.once('value', function(snapshot) {
var data = snapshot.val();
data.forEach(function(dataSnap) {
var index = word.indexOf(' ');
var first = dataSnap.Name.substring(0, index);
var last = word.substring(index + 1);
var candidate = dataSnap.Name;
if (candidate.indexOf(first) >= 0 && candidate.indexOf(last) >= 0)
return dataSnap.CID;
});
});
}
And here is sample code to use the module:
var nameDB = require('./fire.js');
console.log(nameDB('John Doe'));
If I were to do console.log of the module, it returns the intended result however when I make it a module and call it from another file it returns undefined. I realize the module call happens before the function completely runs. How would I fix this?