How To Connect MySQL Database in Node Js App

How To Connect MySQL Database in Node Js App

In this article, we will explain to you how to connect MySQL database in node js application. If you want to use MySQL server with your node.js application, you need to learn MySQL node.js connection.

We can easily connect MySQL database using MySQL NPM package in node js application. MySQL is a nodejs npm package and it is written in JavaScript so that we can easily connect MySQL with node js.

Node Js Application Setup

First, we will open the command prompt and create the application in our directory. for this, you can follow the below command.

Install NPM Package

After the done setup node js application, we will install the express and MySQL npm package. so you can see the following npm command.

Create Database Connection

In this step, We will create a config.js file in the node js application. after that, we will configure the database connection.

How to Connect Node.js to MySQL Database

In this step, We will create a server.js file and set up the node js application using express.

Run Node js Application

we will run the node js application using the below command. so you can follow the below command.

Now you can run the example using the below Url in the browser.

Please follow and like us: