Database
MySql
Node JS Mysql Connection Example
This is a short guide on node js mysql connection example. you will learn how to connect mysql database in node js. we will help you to give example of how to use mysql in node js. step by step explain mysql connection in node js.
- 4.5/5.0
- Last updated 08 September, 2022
- By Admin
In this example, i will give you simple example of how to connect mysql database using node js. i am not going to explain you in more details, but give you simple example, so let's see example.
Install MySQL
you have to install mysql using bellow npm command
npm install mysql
server.js : Mysql Database Connection
var mysql = require('mysql'); var connection = mysql.createConnection({ host: "localhost", database : 'laravel8_blog', user: "root", password: "root" }); connection.connect(function(err) { if (err) throw err; console.log("Connected!"); }); connection.query('SELECT * FROM events', function (error, results, fields) { if (error) throw error; results.forEach(result => { console.log(result); }); }); connection.end();
now you can run project by following command:
node server.js
you will see layout as like bellow:
I hope it can help you...
Categories
PHP
(5)
Codeigniter
(5)
Laravel
(3)
JS
(1)
Angular JS
(5)
Node JS
(5)
Vue JS
(4)
React JS
(6)
jQuery
(5)
Javascript
(3)
jQuery UI
(6)
Wordpress
(1)
Python
(5)
Database
(1)
MySql
(5)
Mongo DB
(1)
DBMS
(1)
SQL
(5)
HTML
(1)
HTML 5
(5)
CSS
(5)
Bootstrap
(5)
Ajax
(5)
JAVA
(1)
JSON
(5)
Ubuntu
(5)
Server
(5)
Git
(3)
Google
(1)
Google Map
(7)
Google API
(1)
Elastic Search
(1)
Apache
(1)
Installation
(1)