Here are my codes:
var express = require('express');
var app = express();
var mysql = require('mysql');
var connection = mysql.createConnection({
host : 'localhost',
user : 'root',
password : '1',
database : 'test'
});
connection.connect();
app.configure(function(){
app.set('view engine', 'jade');
app.set('views', __dirname + '/html');
});
app.get('/index/:name',function(req, res){
data = connection.query('SELECT * FROM deneme', function(err, rows, fields){
if(err) throw err;
veri = rows;
return veri;
});
res.render('index', {
title: req.params.name,
data: data
});
});
app.listen(8080);
Shortly I want to print my datas of mysql
INSERT INTO `deneme` (`id`, `name`) VALUES
(1, 'yusuf'),
(2, 'ali');
When I call localhost:8080/index/yusuf it shows below:
[object Object]
What can i print datas?
EDIT
My index.jade file:
!!! 5 html head title= title body p= data
If you want a string representation, you could use JSON.stringify(myObject).
res.render('index', {
title: req.params.name,
data: JSON.stringify(data)
});
But I'm not sure if that's what you want. You probably want to access the data's properties by referencing them: #{data.someProperty}.
Or you could make the data object return a string representation when it's printed. Here is an example.