I have a problem in my Node.js project. I have some code that goes through an entire list of JSON and prints "1", and also I have some code that is using API and prints "2". Right now the program prints:
2
1
and I want that the program to print:
1
2
My code:
//include libraries
const apigClientFactory = require('aws-api-gateway-client');
const tabletojson = require('tabletojson');
const Promise = require('promise');
//Global variables
const url = '****';
var jsonOutput = {};
//////////////////////1/////////////////////////
//Convert Html tables to Json object
tabletojson.convertUrl(url, function(tablesAsJson) {
var exchangeJson = tablesAsJson[0];
console.log("1");
var j = 0;
for(var i = 0 ;i < exchangeJson.length; i++)
{
jsonOutput[j++] =
{
****
};
}
});
//////////////////////2/////////////////////////
var apigClient = apigClientFactory.default.newClient({
accessKey: '****',
secretKey: '****',
invokeUrl: '****'
});
var pathTemplate = '/staging/rates';
var method = 'POST';
console.log("2");
for (var i = 0; i < jsonOutput.length; i++) {
var body = {
currency: jsonOutput[i].currency,
chain: '****',
buy: parseFloat(jsonOutput[i].buy),
sell: parseFloat(jsonOutput[i].sell)
};
apigClient.invokeApi({city: '****', country: '****'}, pathTemplate, method, {}, body)
.then(function (result) {
console.log(JSON.stringify(result.data));
}).catch(function (result) {
console.log(result);
});
}
What do I need to do?