I'm trying to make a DB request before all my other code.
Heres what I have so far:
(() => {
const initParams = {
TableName: table,
Key: {
'userId': from.toString(),
}
};
dynamo.get(initParams, function (err, data) {
if (err || isEmpty(data)) {
console.log("INIT ERROR ----------------------------------",
JSON.stringify(err, null, 2));
firstTimeUser = true;
} else {
console.log("INIT SUCCESS---------------------------------",
JSON.stringify(data, null, 2));
firstTimeUser = false;
//user exists
userData = data.Item;
}
});
})();
But: My subsequent code is executed before the IFEE is finished, and thus has no data.
How do I wait until the data has arrived before proceeding?