Menu Close

Connecting to the MySQL database using NodeJs

Connecting to the MySQL database using NodeJs

Install MySQL NPM package

Open the comment prompt and go to directory and run comment

C:\>npm install mysql 

Then create the database connection with nodejs using below code.

var mysql = require('mysql');

var connection=mysql.createConnection({

connection.connect(function(err) {
  if (err) throw err;
  console.log("Database Connected!");

Then run the node comment to check the result

C:\>node mysql.js

Output will be: Database Connected! 

View More Details about the MySQL package –

Posted in NodeJs, NPM

You can also read...

Leave a Reply

Your email address will not be published. Required fields are marked *