我正在研究一个项目,其中nodejs程序在单独的文件中调用另一个程序。
这就是我添加两个:
的方式var ocr = require('./index.js'); //this imports the file
var arr = ocr.ocr_pan(); //this calls the function in that file
不确定,但我猜问题是该过程在ocr.ocr_pan()返回结果之前恢复了结果,var arr不确定。
或从ocr.ocr_pan()
返回结果时存在一些问题我只使用返回。
我也尝试了以下方法:如何从nodejs中的模块返回数组
不起作用
还可以做些什么?
假设此文件与index.js
文件相同,index.js
中的代码应该是这样的:
// Write your function
var ocr_pan = function() {
// Do whatever you like
return result;
};
// Export it, make publicly visible to other files
module.exports = {
ocr_pan: ocr_pan
};