javascript - throw err; ReferenceError: document is not defined -


router page

 var express = require('express');     var router = express.router();     var mysql = require('mysql');              /* home page */     router.get('/', function(req, res, next) {         res.render('mysql', {             title: '',         });     });      var connection = mysql.createconnection({         host : '',         user : '',         password : '',         database : ''     });      connection.connect();             connection.query('select hashtag recipients', function(err, rows, fields) {       if (!err) {         console.log(rows);                     document.getelementbyid('recipients').innerhtml = rows;             }       else {         console.log('error while performing query.');     }      });             connection.end();             module.exports = router; 

views page

<html> <head>  </head> <body> <p id='recipients'></p> <p id='error'></p>  <script> </script>  </body> 

please research before start using platform. node.js may java-script there major difference between node.js , conventional java-script used in browser. node.js is server side platform php or python use write web application or other type of application, javascript runs on browser client side used manipulate doms , many other purposes. there plenty of things did wrong.

var express = require('express');  var router = express.router();  var mysql = require('mysql');      /* home page */  router.get('/', function(req, res, next) {    var connection = mysql.createconnection({      host: '',      user: '',      password: '',      database: ''    });      connection.connect();      connection.query('select hashtag recipients', function(err, rows, fields) {      if (!err) {        console.log(rows);        //send rows template engine render html.        res.render('mysql', {          rows: rows,        });      } else {        console.log('error while performing query.');      }    });    connection.end();  });
<html>    <head>    <title>something here</title>  </head>    <body>    <table>      <tr>some heading</tr>      <% for(var i=0; i< rows.length; i++) {%>        <tr>          <td>            <!-- row[i].key access value object -->                       <%= row[i].somekey%>          </td>        </tr>        <% } %>    </table>  </body>    </html>

now have made assumption use ejs template engine. , not working example snippet on how should work. may this tutorial helps trying do. should read this


Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -