I am running a server on node.js. When I look at the result inside Google Chrome by typing localhost:3030 it returns the value [object Object]
.
this is the app.js code here:
var express = require('express');
var mysql = require('mysql');
var app = express();
app.set("view engine", "ejs");
var connection = mysql.createConnection({
host: 'localhost',
user: 'abcdefg',
password: 'password',
database: 'test'
});
app.get("/", function(req,res){
var q = "select * from showdata";
connection.query(q, function(err, results){
if(err) throw err;
var products = results;
res.render("home", {data: products});
});
});
app.listen(3030, function(){
console.log("server running on 3030");
})
and this is the .ejs file:
<h1>Test</h1>
<p> <strong><%=data%></strong></p>
No errors show up. It just says [object Object]
, whereas it should return all values from the query.