i

Connecting to SQL

MySQL is a relational database and node has several modules available to connect to it.

Mysql module is built-in module available to connect with MySQL database. To use this module, lets download it from npm

Using

>npm I MySQL

Further, Let us see the same with an example.

mySql-demo.js

In above example, we have created two functions for authenticating user and adding user to Book

This application is similar to preceding example where we have used MongoDB.

In AuthenticateUser method, we will take username and password from user and authenticate the user; if the user is authenticated fine, then call the callback function as in the example.

For AddUSer, we can add a user to Users table in the books database and if the book added successfully then the callback function will get executed.