Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Object Promise returned and output rather than value

I have been looking through promise questions for the last hour and am totally clueless so I decided to write a question as I am unable to store the value of the function in a variable without it resulting in a promise.

const T = require("tesseract.js");

async function imageCheck(T, url){
    T.recognize(url, 'eng')
    .then(out => {return(out.data.text)});
}
url = imageCheck(T, 'EXAMPLEURL');
Promise.resolve(url)
console.log("the url is "+url)

My output is:

the url is [object Promise]

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

The Promise.resolve() will return another Promise. You should use then to get value.

MDN Documentation

I would recommend the following ways.

const T = require("tesseract.js");

async function imageCheck(T, url){
    const out = await T.recognize(url, 'eng');
    return out.data.text;
}

imageCheck(T, 'EXAMPLEURL')
  .then( url => console.log("the url is "+url));

OR

const T = require("tesseract.js");

async function imageCheck(T, url){
    return T.recognize(url, 'eng');
}

imageCheck(T, 'EXAMPLEURL')
   .then(out => console.log("the url is "+out.data.text));
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading