How to save connection result in a variable in Node.js ?
We are going to use the query function in MySQL library in node.js that will return our output as expected. Using this approach, we can save connection result in a variable in Node.js.
Setting up environment and Execution:
Step 1: Initialize node project using the following command.
Step 2: Turn on MySQL Database
Step 3: After creating the NodeJS application, Install the mysql module using the following command.
npm install mysql
Database Table: Our sample gfg_table database with look like this.
Step 4: Create an index.js file with the following code.
Step 5: Run the index.js file using the following command.