Node.js-mysql
Can be used in database applications
MySQL database To be able to experiment with the code examples, you should install MySQL on your computer.
You can download the free MySQL database from https://www.mysql.com/downloads/
Install the mysql module
C:UsersYour Name>npm install mysql
Use the mysql module in the application
var mysql = require('mysql');
Create a mysql connection
var mysql = require('mysql');
var con = mysql.createConnection({
host: "localhost",
user: "yourusername",
password: "yourpassword"
});
con.connect(function(err) {
if (err) throw err;
console.log("Connected!");
});
Save a file named demo_node_mysql.js
Then run the file
node dem_node_mysql.js
The result displays
Connected!
Indicates a successful connection