node.js - Connecting to database in Express -
trying connect database using express i new express(i have used nodejs), i trying connect database , display simple json resultant output i tried below code var express = require('express') , http = require('http'); var app = express(); var connection = mysql.createconnection({ host: 'localhost', user: 'root', password: "root", database: 'restaurant' }); // environments app.set('port', process.env.port || 7002); app.get('/',function(request,response){ connection.query('select * restaurants', function(err, rows, fields) { console.log('connection result error '+err); console.log('no of records '+rows.length); response.writehead(200, { 'content-type': 'application/json'}); response.end(json.stringify(rows)); }); } ); http.createserver(app).lis