Getting Started With Node – Course

MySQL with Node

MySQL is a very popular database and been used in millions of application. We can use MySQL with Node as well.

We need to install the module name as mysql to use it with MySQL database.

You need to have MySQL database installed in your system before proceeding.

To install the module:

npm install --save mysql

Here is how we can establish the connection to MySQL engine.

const mysql = require('mysql');

const pool = mysql.createPool({
    connectionLimit : 100, //important
    host     : 'localhost',
    user     : 'root',
    password : '',
    database : 'wordpress',
    debug    :  false

pool.query('SELECT * from users LIMIT 10', (err, rows) => {
     if(err) {
        console.log('error occurred during the connnection.');

You can execute the queries such as INSERT, UPDATE and DELETE in a similar fashion.

Learn more in detail about using Node and MySQL.

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.