Привет!
есть такой index.js
const express = require('express')
const bodyParser = require('body-parser')
const vseval = require('./requests/apival')
const app = express()
app.set('view engine', 'ejs')
app.use(express.static('public'))
app.use(bodyParser.urlencoded({extended: true}))
app.get('/', (req, res) => {
res.render('index', {valiki: false})
})
app.get('/active', async (req, res) => {
const valiki = await vseval('active')
console.log('valiki = ', valiki)
res.render('index', {valiki: valiki})
})
app.listen(3333, () => {
console.log('Server started on port 3000')
})
и имеется подключаемый модуль apival.js:
const rp = require('request-promise')
const { exec } = require("child_process");
module.exports = async function(status){
if (status == 'active') {
tmp = "haqqd q staking validators -o json --limit=1000 \| jq \'\.validators[] \| select(\.status==\"BOND_STATUS_BONDED\")' \| jq -r \'\.tokens \+ \" \" \+ \.description\.moniker \+ \" \" \+ \.commission\.commission_rates\.rate\' \| sort -gr \| nl"
}
else {
uri = 'https://haqq-t.api.manticore.team/cosmos/staking/v1beta1/validators?status=BOND_STATUS_UNBONDING&pagination .limit=500'
}
this.execCommand = function(tmp, callback) {
tmp = "haqqd q staking validators -o json --limit=1000 \| jq \'\.validators[] \| select(\.status==\"BOND_STATUS_BONDED\")' \| jq -r \'\.tokens \+ \" \" \+ \.description\.moniker \+ \" \" \+ \.commission\.commission_rates\.rate\' \| sort -gr \| nl"
exec(tmp, (error, stdout, stderr) => {
if (error) {
console.error('exec error: ${error}');
return;
}
callback(stdout);
});
}
execCommand('SomeCommand', function (returnvalue) {
console.log(returnvalue)
});
}
apival.js содержил exec. Как я могу вернуть результат выполнения exec в переменную в index.js, чтобы поотом отправить на вид?