2021-12-24
2641
#node
Samuel Olusola
84005
Dec 24, 2021 â‹… 9 min read

How to use EJS to template your Node.js application

Samuel Olusola Software engineer (JS stack, GoLang incoming…) and student of computer science at the University of Lagos.

Recent posts:

Implementing Infinite Scroll In Next Js With Server Actions

Implementing infinite scroll in Next.js with Server Actions

Infinite scrolling in Next.js no longer requires external libraries — Server Actions let us fetch initial data directly on the server.

Rahul Chhodde
Apr 19, 2024 â‹… 10 min read
Integrating Django Templates With React For Dynamic Webpages

Integrating Django templates with React for dynamic webpages

Create a dynamic demo blog site using Django and React to demonstrate Django’s server-side functionalities and React’s interactive UI.

Kayode Adeniyi
Apr 18, 2024 â‹… 7 min read
Using Aoi Js To Build A Bot For Discord

Using aoi.js to build a bot on Discord

Explore how the aoi.js library makes it easy to create Discord bots with useful functionalities for frontend applications.

Rahul Padalkar
Apr 17, 2024 â‹… 9 min read
Web Components Adoption Guide: Overview, Examples, And Alternatives

Web Components adoption guide: Overview, examples, and alternatives

Evaluate Web Components, a set of standards that allow you to create custom HTML tags for more reusable, manageable code.

Elijah Asaolu
Apr 16, 2024 â‹… 11 min read
View all posts

7 Replies to "How to use EJS to template your Node.js application"

  1. please help when i used localhost:8080 the response on the navigator is :

    Error: Failed to lookup view “pages/index” in views directory “C:\Users\PC\Desktop\server\views”
    at Function.render (C:\Users\PC\Desktop\server\node_modules\express\lib\application.js:580:17)
    at ServerResponse.render (C:\Users\PC\Desktop\server\node_modules\express\lib\response.js:1017:7)
    at C:\Users\PC\Desktop\server\app.js:8:10
    at Layer.handle [as handle_request] (C:\Users\PC\Desktop\server\node_modules\express\lib\router\layer.js:95:5)
    at next (C:\Users\PC\Desktop\server\node_modules\express\lib\router\route.js:137:13)
    at Route.dispatch (C:\Users\PC\Desktop\server\node_modules\express\lib\router\route.js:112:3)
    at Layer.handle [as handle_request] (C:\Users\PC\Desktop\server\node_modules\express\lib\router\layer.js:95:5)
    at C:\Users\PC\Desktop\server\node_modules\express\lib\router\index.js:281:22
    at Function.process_params (C:\Users\PC\Desktop\server\node_modules\express\lib\router\index.js:341:12)
    at next (C:\Users\PC\Desktop\server\node_modules\express\lib\router\index.js:275:10)
    i used your demonstration
    thank you for help

  2. While passing location of file to res.render(), the views directorry act as home directory. So a file named index.ejs in views folder would have to be passed as res.render(‘index’)

  3. Don’t forget to enable ejs in your vs code inorder for the ejs pages to work . simply go the market place (Extensions )and install EJS Language Support.

    And also sometimes some errors happen because you have not restarted the server, whenever you experience an error yet everything is correct, just restart your server

Leave a Reply