I fetched my api and inserted the data into array.
And then I tried to insert every item in array into Mysql database.
But execution of code only return 3 items not 20 items(length of array).
My code is below:
const label = [];
const calories = [];
const getData = async () => {
const response = await axios.get(
`https://api.edamam.com/api/recipes/v2?type=public&q=egg&app_id=${APP_ID}&app_key=${APP_KEY}`
);
const data = response.data.hits;
data.map((item) => {
label.push(item.recipe.label); //label object in api
calories.push(item.recipe.calories); //calories object in api
});
app.post("/books", (req, res) => {
for (var i = 0; i < label.length; i++) {
const q = "INSERT INTO apiData (`name`, `calories`) VALUES (?)";
var values = [label[i], calories[i]];
db.query(q, [values], (err, data) => {
if (err) return res.json(err);
return res.json("Data created successfully!");
});
}
});
};
getData();
I’m using postman to post into mysql.
When I click send button in POST mode, it returns below
return image
If anyone knows what’s the problem please let me know
THank you