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:

A Guide To The React UseReducer Hook

A guide to the React useReducer Hook

The useReducer React Hook is a good alternative to tools like Redux, Recoil, or MobX.

Ejiro Asiuwhu
Oct 10, 2024 â‹… 13 min read
Using The Built-In SQLite Module In Node.js

Using the built-in SQLite module in Node js

Node.js v22.5.0 introduced a native SQLite module, which is is similar to what other JavaScript runtimes like Deno and Bun already have.

Amazing Enyichi Agu
Oct 10, 2024 â‹… 12 min read
Understanding and supporting zoom behaviors on the web

Understanding and supporting zoom behaviors on the web

Understanding and supporting pinch, text, and browser zoom significantly enhances the user experience. Let’s explore a few ways to do so.

Fimber Elemuwa
Oct 9, 2024 â‹… 7 min read
Comedy and tragedy masks symbolizing Playwright Extra's ability to extend Playwright with customizable plugins for both stealth and interactive browser automation tasks.

Playwright Extra: extending Playwright with plugins

Playwright is a popular framework for automating and testing web applications across multiple browsers in JavaScript, Python, Java, and C#. […]

Antonello Zanini
Oct 8, 2024 â‹… 9 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