Database connection with Nodejs and print data to browser

Install Node.js

Open Command prompt  start server

Run below command in command prompt
npm install mysql

var http = require('http');
var mysql = require('mysql');
var connection = mysql.createConnection({
host: 'hostname',
user: 'username',
database: 'dbname',
port: 3306

console.log('MySQL Connection details  '+connection);

http.createServer(function (request, response)
console.log('Creating the http server');
connection.query('SELECT * FROM user', function(err, rows, fields)
console.log('Connection result error '+err);
console.log('no of records is '+rows.length);
response.writeHead(200, { 'Content-Type': 'application/json'});