Thursday 13 April 2017

Merge sql data fetched from node and populate/merge with table from html?

Hey Node community I was able to connect and retrieve data from the data base using node, serve html pages to a browse and now I have to use that data to populate a table that is HTML based. Is there any way to do this . I haven't found a way for node to talk to pass that info to HTML or found a way for HTML to expect data from node. Essentially how do they talk to each other efficiently. I am aware of sequelize but i just want to render the html file and the data i get from the relational database. here is some code. I am able to only show 1 at a time per route. Either the data retrieved from the DB or the html file i am serving but i need to serve both because i essentiall need to popululate a grid from html with data from node and My relational db(MariaDB).//conecting to data base var mysql = require('mysql'); var express = require('express'); var path = require('path'); var app = express(); var http = require ('http'); var fs = require('fs');var connection = mysql.createConnection({ host: 'localhost', user: 'root', password: '1234', database: 'testdb' }); //-------------// sql app.get('/', function(req, resp){ //sql call connection.query ("SELECT full_name FROM users WHERE user_id = 2 ", function(error, rows, fields ){ if (!!error){ console.log('error in the query');} else { console.log('successful query') resp.send('Hello ' + rows[0].full_name ); } }); })app.get('/', function(req, resp){resp.sendFile('index.html');}) //sets the port app.listen(8080);

Submitted April 13, 2017 at 09:40PM by cyberninja007

No comments:

Post a Comment