Learn To Use Node.js With MySQL

Mani Shankar
7 min readNov 4, 2020
Credit: codedamn

Node.js MySQL is one of the external libraries of Node.js. It helps Node.js developers to connect to MySQL database and execute MySQL Queries.

First of all learn to install MySQL module in Node.js using npm, and use SQL statements with some examples which can make some understanding of Nodejs as well as MySQL integration.

Following is the short way to learn about Node.js and MySQL:-

Install MySQL in Node.js

As Node.js MySQL is an external module, it can be installed using NPM (Node Package Manager).

Need to run the following command in terminal or command prompt to install MySQL module and use it in Node.js programs.

$ npm install mysql

After successful install, need MySQL module in node.js programs by declaring its usage with a require statement as shown below.

var mysql = require('mysql');

Create Connection to MySQL Database

To create a connection variable with IP Address (of server where MySQL server is running), User Name and Password (of user that has access the MySQL database). The following example has to be use:

var con = mysql.createConnection({

--

--

Mani Shankar
Mani Shankar

Written by Mani Shankar

Computer Engineer by profession, passionate about writing fictional stories,technical articles, blogging etc.

No responses yet