0

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

INPUTS TO INSERT DATA MANUALLY

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,
        },
      ]);
    });
  };
  • [Please do not upload images of code/data/errors.](//meta.stackoverflow.com/q/285551). Also: what is your question? [ask] – Olaf Kock Nov 04 '22 at 07:08
  • how can i insert bulk information from api to database – yandry santana Nov 04 '22 at 07:10
  • Does this answer your question? [How do I do a bulk insert in mySQL using node.js](https://stackoverflow.com/questions/8899802/how-do-i-do-a-bulk-insert-in-mysql-using-node-js) – KcH Nov 04 '22 at 07:24
  • no because i can do that already that inserts bulk information but manually not from an api – yandry santana Nov 04 '22 at 07:27

0 Answers0