Everything works just fine I'm just new to js and web programming and non-experienced with async functions. I had tried with Promises with then() and couldn't do it. I'm trying to pass the data isbn number to data1 object
let isbn = "";
//
req.files.imageFile.mv(imageAddress, function (error) {
if (error) {
console.log("Couldn't upload the isbn image file.");
console.log(error);
} else {
console.log("Image file successfully uploaded!");
readText(imageAddress)
.then(isbnNumber => {
}).catch()
}
});
var data1 = {
bookName,
isbn,
};
From this async function that recognize text and parse it as i want
async function readText ( imageAddress ) {
await worker.load();
await worker.loadLanguage("eng");
await worker.initialize("eng");
const {
data: { text },
} = await worker.recognize( imageAddress );
console.log(text);
await worker.terminate();
//get the isbn number from readed text
let textArr = text.split("\n");
var isbnText = "";
var i;
for(i= 0; i < textArr.length; i++){
var str = textArr[i];
if (str.includes("ISBN")){
isbnText = textArr[i];
}
}
isbnText = isbnText.replace("ISBN", "");
let isbnNumber = isbnText.replace(/-/g, "");
isbnNumber = isbnNumber.replace(/\D/g, '')
console.log(isbnNumber);
return isbnNumber;
}
I want to equelize to isbn which is declared outside of the function
readText(imageAddress)
.then(isbnNumber => {
isbn = isbnNumber;
}).catch()