Node.js MySQL Insert Records

INSERT INTO statement is used to insert records in MySQL.

Example

Insert Single Record:

Insert records in "employees" table.

Create a js file named "insert" in DBexample folder and put the following data into it:

Now open command terminal and run the following command:

Node.js insert record 1

Check the inserted record by using SELECT query:

SELECT * FROM employees;

Node.js insert record 2

Insert Multiple Records

Create a js file named "insertall" in DBexample folder and put the following data into it:

Now open command terminal and run the following command:

Output:

Node.js insert record 3

Check the inserted record by using SELECT query:

SELECT * FROM employees;

Node.js insert record 4

The Result Object

When executing the insert() method, a result object is returned.The result object contains information about the insertion.

It is looked like this:

Node.js insert record 5




Latest Courses