mysql - Need help in node.js Jade -


I would like to help to display my SQL record in node. JS I node The basic tutorials are followed by JS and this is the default index. Unable to work by displaying Z, but when I start implementing mySQL connection link and function in my index.js, it does not display to anyone and does not show any data on the browser. Hope you guys can help me as soon as possible, thanks in advance, people

This is my app. Js:

  WORD Express = Expected ('Express'); Var path = requirement ('path'); Var favicon = is required ('static-favicon'); Var Loger = Required ('Morgan'); Var requires cookieParser = ('cookie-parser'); Var bodyParser = is required ('body-parser'); Var index = is required ('./root/index'); Var requires user = ('./routes / users'); Var app = express (); // View engine setup app.set ('views', path.join (__dirname, 'views')); App.set ('visual engine', 'EJS'); App.set ('port', process.env.port || 3000); App.use (favicon ()); App.use (logger ('god')); App.use (bodyParser.json ()); App.use (bodyParser.urlencoded ()); App.use (cookieParser ()); App Use (express.static (path.join (__derename, 'public')); App.use ('/', index); App.use ('/ user', user); /// hold 404 and further error handler app.use (function (req, res, next) {var err = new error ('not found'); err.status = 404; next (err);}); /// Error handler // Development error handler // Print will print if if (app .get ('env') === 'development') {app.use (function (error, request, ridge, next) {res. Status (err.status || 500); res.render ('error', {message: err.message, error: err});}); } // Production Error Handler // No stacktrace user is not leaked to the app. Use (function (mistake, rick, race, next) {res.status (err.status || 500); res.render ('error', {message: Err.message, error: {}})}}; Module .exports = app; var server = app.listen (app.get ('port'), function () {console.log ('listen at port% done', server.address (). Port);}); < / Code> 

This is my route / index.js:

  var express = require ('express'); Var router = express .routor (); var mysql = required ('mysql'); var conn = {host: 'localhost', user: 'user', password: 'password', database: 'rest_api', port: '3306'}; / * Get home page * / Router.get ('/', function (Rick, Res) {export.index = functio N (req, res) {var connection = mysql.create connection (conn); var query = 'SELECT sensorId, sensors, pinNo, sensorType (sensorInfo'), connection.query (query, function (mistake, rows, field) {If (mistake) becomes a mistake; res.render ('index', {title: 'sensor REST API', 'items': rows})}});};}); Module.exports = router; < / Code> 

This is my / views / index.jade:

  Layout blocks content increases in h1 = title p # Welcome {title} table tr sensor id th th th th th pin number th censor type - every item in the item tr tid = Item.Sensorid TD = item.sensors TD = item.pinNo TD = item.sensorsType  

This is my sensor INFODA structure:

 

This is my record that I want to show it out of my sensor:

Data dumping table for <-> - - Enter the value (1, 1, 'red LED', 7, 'switch on / off') in `sensor info '-` sensor info' (`id`,` sensor id`, `sensor`, 'pino', 'sensor type) OFF '), (2, 2,' Blue LED ', 11,' Switch On / Off '), (3, 3,' Green LED ', 13,' Switch On / Off ');

Remove the export call from your router function -

  Exports.index = function (req, res) {var connection = mysql.createConnection (conn); Var query = 'Select sensor ins, sensor, pinano, sensor type to sensor infonn'; Connection.query (query, function (fault, rows, field) {If (mistake) becomes a mistake; res.render ('index', {title: 'sensor REST API', 'item': lines});} ); };  

to

  var connection = mysql.createConnection (conn); Var query = 'Select sensor ins, sensor, pinano, sensor type to sensor infonn'; Connection.query (query, function (fault, rows, field) {If (mistake) becomes a mistake; res.render ('index', {title: 'sensor REST API', 'item': lines});} );  

Comments

Popular posts from this blog

sqlite3 - UPDATE a table from the SELECT of another one -

c# - Showing a SelectedItem's Property -

javascript - Render HTML after each iteration in loop -