im beginner in Node.js and i have a problem... I dont know how send rows from server file to client file. example:
var app = require("http").createServer(handler)
var fs = require("fs");
var mysql = require('mysql');
var url = require('url');
app.listen(1337);
var connection = mysql.createConnection({
host: 'localhost',
user: 'root',
password: '',
database: 'wordpress1'
});
connection.connect();
connection.query("SELECT * FROM wp_comments", function(err, rows, fields) {
rows[1].comment_author; // How send this to client file?
});
function handler(request, response) {
var pathname = url.parse(request.url).pathname;
if(pathname === "/") {
fs.readFile('mysql.htm', function(err, content) {
response.writeHead(200);
response.end(content);
});
}
}
and client file:
<!DOCTYPE html>
<html>
<head>
<title>dsfsd</title>
<meta charset="UTF-8">
</head>
<body>
<script>
// how to display a rows in this file?
</script>
</body>
</html>
i heard something about common.js, require.js etc. but i dont know whether is this good way to build a node application?