Node.js MySQL Insert into Table
In this article, we are going to learn how to insert rows into an SQL table using Node.js.With the help of SQL INSERT Query.
Initialize Node.js project:
npm install express npm install mysql
MySQL Database Structure:
gfg_db DATABASE. gfg_table (id INT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(255), address VARCHAR(255)).
Anytime we want to make a query we will import the db_con module in that file. This will increase the modularity of our code.
Inserting Single Row: Below is a Route function to insert single row.
Row inserted with id = 1
Inserting Multiple Rows: Below is a Route function to insert multiple rows.
All Rows Inserted