const fetch = require("node-fetch"); const fs = require("fs"); let VisionApi = function (pathImage) { let imageBytes = fs.readFileSync(pathImage).toString("base64"); let body = { requests: [ { image: { content: imageBytes, }, features: [ // { // type: "TEXT_DETECTION", // }, // { // type: "FACE_DETECTION", // }, // { // type: "LANDMARK_DETECTION", // }, // { // type: "LOGO_DETECTION", // }, // { // type: "LABEL_DETECTION", // }, { type: "DOCUMENT_TEXT_DETECTION", }, // { // type: "SAFE_SEARCH_DETECTION", // }, // { // type: "IMAGE_PROPERTIES", // }, // { // type: "CROP_HINTS", // }, // { // type: "WEB_DETECTION", // }, // { // type: "PRODUCT_SEARCH", // }, // { // type: "OBJECT_LOCALIZATION", // }, ], }, ], }; let headers = { "x-origin": "https://explorer.apis.google.com", "content-type": "application/json", "Content-Type": "text/plain", }; return new Promise((resolve, reject) => { fetch( "https://content-vision.googleapis.com/v1/images:annotate?alt=json&key=AIzaSyAa8yy0GdcGPHdtD083HiGGx_S0vMPScDM", { method: "post", body: JSON.stringify(body), headers: headers, } ) .then((res) => res.json()) .then((json) => { resolve(json); }); }); }; VisionApi("./image/test.jpg").then((result) => { console.log(result.responses[0].fullTextAnnotation.text); });