Node JS - Node js Create Connection with MySQL - Node - Node JS tutorial - webnode




  • We can use Node.js in database applications. Here we use MySQL as a database with Node.js.

Install MySQL on your computer

  • Once the MySQL is installed and running, you can access it by using Node.js.

Install MySQL Driver

  • You have to install MySQL driver to access a MySQL database with Node.js.
  • Download MySQl module from npm.
  • To download and install the "mysql" module, open the Command Terminal and execute the following:
  • npm install mysql
 npm install mysql

Learn Node js - node js Tutorial - npm install mysql - node - Node js Examples

Create Connection

  • Create a folder named "DBexample". In that folder create a js file named "connection.js" having the following code:

connection.js

var mysql = require('mysql');  
var con = mysql.createConnection({  
host: "localhost",  
user: "wikitechy",  
password: "wikitechy12345"  
});  
con.connect(function(err) {  
if (err) throw err;  
console.log("Connected!");  
});  

 node-js mysql create connection

Learn Node js - node js Tutorial - node-js mysql create connection - node - Node js Examples

  • Now open the command terminal and use the following command: Node connection.js

Output:

 nodejs node connection

Learn Node js - node js Tutorial - nodejs node connection - node - Node js Examples

  • Now Node.js is connected with MySQL.

This wikitechy technological portal provides you whole lot of information related to the topics such as mongodb tutorial , what is node js , express js tutorial , node js tutorial pdf , learn node js , node js tutorial for beginners , node js tutorial w3schools , node js express , javascript for beginners , node js express tutorial , node js tutorial point , node js book , node js server , note js , node js mongodb , what is node js used for , why node js , node tutorial , node js basics , tutorialspoint node js , node express , node js sample application , nodeschool , node js for beginners , express tutorial , node js application , use of node js , npm tutorial , node js org , node js training , node js online training , node js tutorial beginner , how to use node js , node js hello world , express node js , node js mongodb tutorial , nodejs http , why use node js

Related Searches to Node.js Create Connection with MySQL