node.js - 没有从谷歌视觉 API 获得正确的输出格式
问题描述
输出在 console.log() 中正确显示,但是当我将其导出并使用 res.end() 时,它会显示其他内容。
这是我得到的输出 [1]:https ://i.stack.imgur.com/RWj65.png
ocr.js
const vision = require('@google-cloud/vision');
process.env.GOOGLE_APPLICATION_CREDENTIALS = 'C:/Users/animesh/Downloads/polished-signer-319320-9bf98d18ed89.json'
async function quickstart() {
try {
// Creates a client
const client = new vision.ImageAnnotatorClient();
// Performs text detection on the local file
const [result] = await client.textDetection('so.jpg');
const detections = result.textAnnotations;
***const [ text ] = detections
const data = text.description ;
console.log(data);
module.exports = data**;*
} catch (error) {
console.log(error)
}
}
quickstart()
索引.JS
const http = require('http');
const data = require("./Home.js")
const port = process.env.PORT || 3000;
const server = http.createServer((req, res)=>{
res.setHeader('Content-Type', 'text/html')
console.log(req.url)
console.log(data);
if(req.url == '/'){
res.statusCode = 200;
**res.end(data.toString());**
}[enter image description here][1]
})
server.listen(port, ()=>{
console.log(`Server is listening on port ${port}`);
});
解决方案
推荐阅读
- django - 是否可以在 aws 的单个文件中写入瞭望塔日志
- java - How to allow angular brackets <> without any characters between them using Regex?
- java - Minio 存储桶大小
- angular - 如何将拦截器和服务从应用程序模块加载到延迟加载模块?
- java - 在 Jhipster 中访问文件(Angular + Springboot)
- c# - C# 列出最小和最大范围
- r - 如何使用 R 中的“break”语句解决问题?
- html - 删除密码上的字符后如何删除确认密码上输入的字符?
- html - 根据条件为 HTML 表格正文的文本着色
- android - 如何在片段中的单击侦听器上制作按钮