У меня есть файл с двумя узлами, один узел я назвал test.js
узлом, который находится в папке root, теперь мой другой файл node js в functions/index.js
, я хочу запустить свой тестовый узел в моем индексе. js файл, здесь я поместил свой код файлов, может ли кто-нибудь помочь мне, как получить его данные?
test. js (он находится в папке root)
const GeotabApi = require('mg-api-js');
const authentication = {
credentials: {
database: '***',
userName: '***',
password: '***'
}
}
const api = new GeotabApi(authentication);
api.call('Get', { typeName: 'Group', resultsLimit: 100 })
.then(result => {
return result;
})
.catch(error => {
return error;
});
Я хочу вызвать этот тест. js файл в свой индекс. js, я поместил свой код индекса. js файл, но я не получаю его вывод
функции /index.js
var childProcess = require('child_process');
function runScript(scriptPath, callback) {
// keep track of whether callback has been invoked to prevent multiple invocations
var invoked = false;
var process = childProcess.fork(scriptPath);
// listen for errors as they may prevent the exit event from firing
process.on('error', function (err) {
if (invoked) return;
invoked = true;
callback(err);
});
// execute the callback once the process has finished running
process.on('exit', function (code) {
if (invoked) return;
invoked = true;
var err = code === 0 ? null : new Error('exit code ' + code);
callback(err);
});
}
exports.test_groups_list = functions.https.onRequest(async (req, res) => {
runScript('../test.js', function (err) {
if (err) {
res.set({ 'Access-Control-Allow-Origin': '*' }).send({ "status": 0,"msg":err });
} else {
res.set({ 'Access-Control-Allow-Origin': '*' }).send({ "status": 1 });
}
});
});