SQL uses following INSERT statement to insert data in tables.
Insert Single Record
Create a JavaScript file in your application to insert data to table using Node.js application.
vim insert_mysql_data.js
Add the following content.
Execute the JavaScript file using node. On successful execution you will get results like below.
node insert_mysql_data.js Output: Database connected successfully! 1 record inserted
Insert Multiple Records
You can also insert multiple records into the database table. Create a JavaScript file in your application to insert data to table using Node.js application.
vim insert_multi_record_mysql.js
Add the following content. We have created an array of records then inserted into the database.
Execute the JavaScript file using node. On successful execution you will get results like below.
node insert_multi_record_mysql.js Output: Database connected successfully! 4 record inserted