I make my first web application with nodes and reacc. I do sql query in node.js and show html elements in my page. I need help getting the result of sql in my html page as json date. I put some of the code with my experiments, which may be very wrong. Regards.
var React = require('react');
var DefaultLayout = require('./layout/master');
var mysql = require('mysql');
var connection = mysql.createConnection({
port: '3301',
host: 'localhost',
user: 'root',
password: 'root',
database: 'nodedb',
});
connection.connect();
function getArticless() {
connection.query('select * from articles', function(err, result) {
if (err)
JSON.stringify(err);
else
JSON.stringify(result);
});
}
const jsonArticles = getArticless();
var IndexComponent = React.createClass({
render: function() {
return (
<DefaultLayout name={this.props.name}>
<div>
{jsonArticles }
</div>
</DefaultLayout>
)
}
});
module.exports = IndexComponent;
via nnL
No comments:
Post a Comment