Tesseract.js: How To OCR Remote Images from a URL in Node


Tesseract.js is a JavaScript OCR library based on the world’s most popular Optical Character Recognition engine. It’s insanely easy to use on both the client-side and on the server with Node.js.

Server side, Tesseract.js only works with local images. But, with a little help from the request Node package, we can download a remote image from a URL and then OCR it with Tesseract.js. 

We’ll tackle this in three steps:

  1. Write code to download a remote file with Node
  2. Write code to OCR that local file with Tessearct
  3. Put the two snippets together

The final product will take just fifteen lines of JavaScript to OCR images from a URL. Sound good? Let’s get started.

Download a remote file with Node.js

Request “is designed to be the simplest way possible to make http calls” in Node.js. We’ll use it to open a URL and then pipe the stream to the local file system using the Node.js standard library. When finished, we’ll fire off a callback.

Paste this code into a new file called download.js:

We’re using the sample image from the Tesseract documentation, which looks like this:

Install request and run the script:

Check your directory and you should see a new file. Now let’s OCR that downloaded file.

OCR a local image with Tesseract.js and Node.js

Getting started with Tesseract.js is dead simple. Paste this code into a file called ocr.js.

Install Tesseract.js and run the script:

Once Tesseract starts up (~10 seconds on my MacBook Pro), we’ll see progress updates and then find the recognized text in result.text. There’s a ton more data hiding in result if you’re inclined to go digging.


We now have code to download a remote file and code to OCR a local file — we just need to put them together.

OCR a remote image with Tesseract.js

Paste this code into a new file called download-and-ocr.js:

All we’ve done here is:

  • Start with the script from download.js 
  • Require Tesseract.js
  • Paste the the code from ocr.js into the callback that’s run when the file finishes downloading.

Give the script a run, swapping in your own picture URL if you so please:

Next Steps

That’s it! Three simple steps and we’re using Tesseract.js to perform OCR on an image from a URL. My personal motivation is to use Tesseract.js in conjunction with Twilio MMS to process photos that I snap while running around NYC. Perhaps I’ll grep phone numbers out of ads and run them through our Lookup API to see if they’re Twilio numbers. 

What are you going to build?

If you’d like to learn more, check out:

If you enjoyed this post, give a shout-out to Guillermo Webster and Kevin Kwok for their heroic effort porting Tesseract to JS. And, of course, feel free to drop me a line if you have any questions or build something you’d like to show off.

Happy Hacking.

  • James Vaughn

    Nice article, thanks for the post. Did you have time to get further with the project using your phone to take pictures? If so were you able to programmatically align the image so tesseract could read it? I personally would be interested in a follow-up article involving this step..

  • Felipe Machado Almeida

    On First execution of ocr.js file, I get this:
    AdaptedTemplates != NULL:Error:Assert failed:in file ../classify/adaptmatch.cpp, line 190

    function f(a){throw a;}var h=void 0,i=!0,j=null,k=!1;function aa(){return function(){}}function ba(a){return function(){return a}}var n,Module;Module||(Module=eval(“(function() { try { return TesseractCore || {} } catch(e) { return {} } })()”));var ca={},da;for(da in Module)Module.hasOwnProperty(da)&&(ca[da]=Module[da]);var ea=i,fa=!ea&&i;
    abort() at Error
    at Na (/Users/macbook/node_modules/tesseract.js-core/index.js:32:26)
    at Object.ka [as abort] (/Users/macbook/node_modules/tesseract.js-core/index.js:507:108)
    at _abort (/Users/macbook/node_modules/tesseract.js-core/index.js:373:173)
    at $L (/Users/macbook/node_modules/tesseract.js-core/index.js:383:55709)
    at jpa (/Users/macbook/node_modules/tesseract.js-core/index.js:388:22274)
    at lT (/Users/macbook/node_modules/tesseract.js-core/index.js:387:80568)
    at mT (/Users/macbook/node_modules/tesseract.js-core/index.js:387:80700)
    at Array.BS (/Users/macbook/node_modules/tesseract.js-core/index.js:387:69011)
    at bP (/Users/macbook/node_modules/tesseract.js-core/index.js:383:110121)
    at jT (/Users/macbook/node_modules/tesseract.js-core/index.js:387:80280)
    If this abort() is unexpected, build with -s ASSERTIONS=1 which can give more information.

    • Yash Panwer

      hey Felipe same error show when i run this file did u find any solution this problem or not ??

  • gdadsriver

    Hi! Thanks for the article! I wanted to know if it’s possible with tesseract to:

    1. Access the text that’s being processed in a stream.
    2. Can it start recognising the text last line first?