EJS Reference Error

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/
 128| </div><br/><br/>
 >> 130| <%=sec%>
 131| </div>
 132| </div>
 133| </body>

 sec is not defined
 at eval (eval at compile (/home/michaeluy/apps/, <anonymous>:11:23)
 at returnedFn (/home/michaeluy/apps/
 at View.exports.renderFile [as engine] (/home/michaeluy/apps/
 at View.render (/home/michaeluy/apps/
 at tryRender (/home/michaeluy/apps/
 at EventEmitter.render (/home/michaeluy/apps/
 at ServerResponse.render (/home/michaeluy/apps/
 at /home/michaeluy/apps/
 at Layer.handle [as handle_request] (/home/michaeluy/apps/
 at next (/home/michaeluy/apps/

and here is 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: '',
    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

Show comments

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

Sorry to see that your question hasn’t received an answer yet. Unfortunately, after this much time, it is unlikely that an answer for this specific question will be provided. For people still landing here via search, make sure you are passing the view data correctly and that you do not have any EJS syntax errors. If you are still stuck, please post a new question and we’ll help you out.

// this is correct
res.render('index', {
            sec: rows[0].name