From the course: Building a Website with Node.js and Express.js
Unlock the full course today
Join today to access over 24,800 courses taught by industry experts.
Rendering the index page with EJS
From the course: Building a Website with Node.js and Express.js
Rendering the index page with EJS
- [Instructor] 'Kay, now with EJS in place, I want to use it to render the index page, so let's open server.js, and let's look for the route with the slash. So I'll remove what I have here, and I will now use the render function of Express. So I add, response.render, and render takes its first argument, a path to a template. And I use here, pages/index. Obviously, I have to create that, so what Express is doing here, it will then look into views, pages, index, to find a matching template file. As a second argument, it also accepts an object that contains local variables that will be available to the template. And I want to just set a variable that's called pageTitle, and let this be, Welcome. So the page title of the index page should be Welcome. Of course, I now have to also create this pages directory in views, so I add a new folder to views called pages. And then I will move over the index.html file into this…