Here ,I am making an array of objects data2[] and iterating over this array sending each of its objects , I got 1 response in the postman when I checked it , but not others because of this error .
const express = require("express")
const getOrganicData = require('../GoogleSearchScraping/organicData')
const url = require('url');
const router = new express.Router()
router.get('/searchExtended' , async (req, res) =>
{
try {
const queryObject = url.parse(req.url , true).query
console.log("Query is "+queryObject.query);
const data = await getOrganicData(queryObject.query)
const organicData = data[0]
const snippet = data[1]
const htmlSnippet = data[2]
const data2 = new Array(data[0].length)
for (let i = 0; i < data2.length; i++)
{
data2[i] =
{
organicData: organicData[i],
snippet: snippet[i],
htmlSnippet: htmlSnippet[i],
Rank: ""+(i+1)+""
}
}
for (let i = 0; i < data2.length; i++)
{
res.status(201).send(Object.values(data2[i]))
}
}
catch (error) {
res.status(400).send('Error '+error)
}
})
module.exports = router ;