EJS.JS ReferenceError: title not defined

All we need is an easy explanation of the problem, so here it is.

I am having an issue with a script in express. I am calling a function that renders a view, on the success of another function. In this project I am utilizing angular, node, express, and ejs as view engine. When I render the view, I unfortunately receive an ejs error of the following:

ReferenceError: /Users/emilywfrancis/Desktop/nodejs-angularjs-sequelizejs/views/about.ejs:5

3| <html ng-app="app">

4| <meta charset="utf-8">

5| <link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/font-awesome/3.1.0/css/font-awesome.min.css" rel="nofollow noreferrer noopener" />

6| <% include header %>

7| <% include navbar %> 

8| <body>
  title is not defined

Here is the code:

exports.verifyusers= function(req, res) {
where: {
  email: req.body.email,
  password: req.body.password
 }).then(function(res, user) {
    if(user == "user.name") { //if user exists in database

How to solve :

I know you bored from this bug, So we are here to help you! Take a deep breath and look at the explanation of your problem. We have many solutions to this problem, But we recommend you to use the first method because it is tested & true method that will 100% work for you.

Method 1

Seems like the error is actually in the header file which proprely contains something like:

<%= title %>

I think changing changing it to the following will work:

<%= (typeof title != "undefined" ? title : "") %>

Method 2

You need to give your title a value, if not already done.
If it is done, then @andlrc answer is correct, but you still want to figure out why it is throwing an error. If not, it is bad practice.

In your server define a variable names title and give it a string.
Then expose is to your view.

In this answer you find an example.

Note: Use and implement method 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply