Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Reference Error #223

Open
MichaelUyy opened this issue Nov 24, 2016 · 1 comment
Open

Reference Error #223

MichaelUyy opened this issue Nov 24, 2016 · 1 comment

Comments

@MichaelUyy
Copy link

MichaelUyy commented Nov 24, 2016

I have a Node.JS application that is hosted on Ubuntu 16.04. I am using EJS to display queried data from MySQL but I am getting a reference error like this

ReferenceError: /home/michaeluy/apps/michaeluy.me/views/index.html:130
 128| </div><br/><br/>
 129|         
  >> 130| <%=sec%>
  131| </div>
 132| </div>
 133| </body>

 sec is not defined
 at eval (eval at compile (/home/michaeluy/apps/michaeluy.me/node_modules/ejs/lib/ejs.js:485:12), <anonymous>:11:23)
 at returnedFn (/home/michaeluy/apps/michaeluy.me/node_modules/ejs/lib/ejs.js:514:17)
 at View.exports.renderFile [as engine] (/home/michaeluy/apps/michaeluy.me/node_modules/ejs/lib/ejs.js:358:31)
 at View.render (/home/michaeluy/apps/michaeluy.me/node_modules/express/lib/view.js:126:8)
 at tryRender (/home/michaeluy/apps/michaeluy.me/node_modules/express/lib/application.js:639:10)
 at EventEmitter.render (/home/michaeluy/apps/michaeluy.me/node_modules/express/lib/application.js:591:3)
 at ServerResponse.render (/home/michaeluy/apps/michaeluy.me/node_modules/express/lib/response.js:961:7)
 at /home/michaeluy/apps/michaeluy.me/server.js:15:9
 at Layer.handle [as handle_request] (/home/michaeluy/apps/michaeluy.me/node_modules/express/lib/router/layer.js:95:5)
 at next (/home/michaeluy/apps/michaeluy.me/node_modules/express/lib/router/route.js:131:13)`

and here the first bit of my server.js file

var http = require('http');
 var express = require('express');
var fs = require('fs');
var bodyParser = require('body-parser');
var mysql = require('mysql');
var connection  = require('express-myconnection');
var app = express();

app.use('/',express.static(__dirname + '/'));
app.use(bodyParser.urlencoded({ extended: false }));
app.engine('.html', require('ejs').__express);
app.set('view engine','html');

var connection = mysql.createConnection({
    host: '127.0.0.1',
    user: 'root',
    password: '',
    database: 'michaeluy'
});

 app.get('/', function(req, res){
    connection.query("SELECT * FROM messages", function(err, rows, fields){
        if (err) throw err;
        res.render('index', {
            sec: rows[0].name
        });
    });
 });

I have tried using console.log at first to see if it is able to query the data correctly and it did but when I set the code on the html file for it to show up on the page itself. It gives back a reference error.

Hope someone can help here. Thanks in advance`

@mde
Copy link
Collaborator

mde commented Nov 24, 2016

This version of EJS is no longer maintained. The current version (installable by NPM) is here: https://github.com/mde/ejs

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants