NodeJS route title. What is it there for?


Please forgive my ignorance. This is such a basic question I’m almost too embarrassed to ask it, but perhaps it will help some other ignoramus down the line.

In my route:

  , function (req, res) {
    res.render('my-page', { title: 'some page' });

What is the title ‘some page’ for?

I don’t think there’s a HTTP Response title header, so i’m assuming it’s not for that…

Does it simply set a default HTML title element, in case you don’t add a title element in your HTML?

Which would imply that the route renderer checks if you added a title?

Is it necessary to include the { title: 'some page' }

Am I asking a question that I could probably get answered with 2 minutes of playing around. Yes.

Do I want you to link me to some NodeJS/express documentation? No.

Thanks <3



This is just a piece of data that you can use inside your HTML page however you like.

In your case, I assume you are using ejs

So you can open you ejs file and add

<%= title %>

Anywhere in your file and the title value that you passed will show!

So long story short, just a piece of data passed to your ejs file

Answered By – Amr Al-Gendi

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published