Quick Contact


    Node JS and Mysql

    Node JS and Mysql is necessary binding for any web application. Mysql is one of the open source database in world and efficient as well. Almost every programming language like Java or PHP provides driver to access and perform operations with Mysql.

    Open terminal and install Mysql model with:-

    >npm install mysql,

    once it is installed, a node.modules folder is created in which a file is created in which script is wriiten. As first mysql type is required as-:

    Varmysql = require (‘mysql’);

    To create my connection

    Var connection = mysql.createConnection

    ({

    …..

    })

    Node JS and Mysql
    • Now it’s time to connect to a database as-:
    • Connection.connect();

      Node JS and Mysql
    • Open terminal window and run this application be entering >node app
    • But after execution done connection error arrives as-:

      Node JS and Mysql
    • Now solution is with following code which is written in new solution file of this problem.
    • Node JS and Mysql
    • Now create a simple function to format errors in a friendly way-:
    • Node JS and Mysql
    • Now open the terminal and run the file-:
    • Node JS and Mysql
    • Now connection lost is just a message application is still running-:
    • Node JS and Mysql
    • Now connection is still lost. Now what you have to do is delete the some code lines from above as-:
    • As remove “system message function” and “system message in this error” and once it’s done, run the application again and you get no error. Now you can work with MySql database without any error.

    Copyright 1999- Ducat Creative, All rights reserved.