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:

Mastering charts and database visualization with ChartDB

ChartDB is a powerful tool designed to simplify and enhance the process of visualizing complex databases. Explore how to get started with ChartDB to enhance your data storytelling.

David Omotayo
Jan 3, 2025 â‹… 7 min read
JavaScript icon over teal background.

JavaScript scroll snap events for scroll-triggered animations

Learn how to use JavaScript scroll snap events for dynamic scroll-triggered animations, enhancing user experience seamlessly.

Abiola Farounbi
Jan 2, 2025 â‹… 7 min read

Understanding deep linking in React Native

A comprehensive guide to deep linking in React Native for iOS 14+ and Android 11.x, including a step-by-step tutorial.

Eugene Hauptmann
Dec 31, 2024 â‹… 9 min read
React logo over lavender background

How React 19 can help you make faster websites

Explore React 19’s new features, including the compiler, automatic memoization, and updates to hooks like use() and useFormStatus.

Emmanuel Odioko
Dec 31, 2024 â‹… 12 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