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:

Rxjs Adoption Guide: Overview, Examples, And Alternatives

RxJS adoption guide: Overview, examples, and alternatives

Get to know RxJS features, benefits, and more to help you understand what it is, how it works, and why you should use it.

Emmanuel Odioko
Jul 26, 2024 â‹… 13 min read
Decoupling Monoliths Into Microservices With Feature Flags

Decoupling monoliths into microservices with feature flags

Explore how to effectively break down a monolithic application into microservices using feature flags and Flagsmith.

Kayode Adeniyi
Jul 25, 2024 â‹… 10 min read
Lots of multi-colored blue and purplish rectangles.

Animating dialog and popover elements with CSS @starting-style

Native dialog and popover elements have their own well-defined roles in modern-day frontend web development. Dialog elements are known to […]

Rahul Chhodde
Jul 24, 2024 â‹… 10 min read
Using Llama Index To Add Personal Data To Large Language Models

Using LlamaIndex to add personal data to LLMs

LlamaIndex provides tools for ingesting, processing, and implementing complex query workflows that combine data access with LLM prompting.

Ukeje Goodness
Jul 23, 2024 â‹… 5 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