What is “Node.js” exactly?

If you’re reading this article then you must be already familiar with Node.js but if incase you’re just a curious visitor then you should know that Node.js is an asynchronous event driven JavaScript runtime, Node is designed to build scalable network applications.

Prerequisite

An existing or new Google Cloud Platform project or create a new one .

. Enable billing for your project here .

. Enable the Google Cloud Vision API here.

enable the Cloud Vision API

Setup Authentication as owner of the project here .

. Generate a google-services.json key file from your project’s console.

create service account key for your project

Let’s Code!

Let us first create a new npm project and install the dependencies.

starting a new npm project

We’ll use @google-cloud/vision package from npm/Github to get all sorts of data like image classification, object detection, label detection, text detection etc.

Lets setup @google-cloud/vision package in sample.js we created earlier.

#Note: here path to your key json file can be ‘./key/google-services.json’ etc.

google-cloud/vision package setup

Using the vision client to detect text in our sample.js file

async function to detect text

Testing Time!

Let us test it by passing the image path to our detectTextFromImage async function like the below example.

Time to test

Let us pick a simple image with lorem ipsum text to test our code

sample.png for testing

Results

Running our code with sample.png gave the results as expected 🥳

More Examples

@google-cloud/vision package is not only used for text detection it can be used for multiple things like image classification, object detection, label detection and much more.

Another example for label detection

async function to detect labels

Give yourself a pat on the back if you’ve coded along until the very end 😆