i have this api information that i need to insert into mysql database using nodejs. i have made connection to the Database and built a small code that lets me insert data manually.
MY QUESTION how can i insert bulk information from api to database
BACKEND
app.post('/create', (req, res) => {
const position = req.body.position
const name = req.body.name
const alliance = req.body.alliance
const points = req.body.points
db.query("INSERT INTO stats (position, name, alliance, points) VALUES (?,?,?,?)",
[position, name, alliance, points],
(err, result) => {
if (err) {
console.log(err)
} else {
res.send("Values Inserted")
}
}
);
});
FRONTEND
const addStats = () => {
Axios.post("http://localhost:3001/create", {
position: position,
name: name,
alliance: alliance,
points: points,
}).then(() => {
setstatsList([
...statsList,
{
position: position,
name: name,
alliance: alliance,
points: points,
},
]);
});
};