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:

Server-Side Rendering With React Router V7

Server-side rendering with React Router v7

The recent merge of Remix and React Router in React Router v7 provides a full-stack framework for building modern SSR and SSG applications.

Amazing Enyichi Agu
Jan 13, 2025 â‹… 20 min read
debugging javascript web apps

How to master JavaScript debugging for web apps

With the right tools and strategies, JavaScript debugging can become much easier. Explore eight strategies for effective JavaScript debugging, including source maps and other techniques using Chrome DevTools.

Ivy Walobwa
Jan 9, 2025 â‹… 8 min read
A Deep Dive Into Angular’s FormArray Container

A deep dive into Angular’s FormArray container

This Angular guide demonstrates how to create a pseudo-spreadsheet application with reactive forms using the `FormArray` container.

Kayode Adeniyi
Jan 8, 2025 â‹… 3 min read
Handling React Loading States With React Loading Skeleton

Handling React loading states with React Loading Skeleton

Implement a loading state, or loading skeleton, in React with and without external dependencies like the React Loading Skeleton package.

Ibadehin Mojeed
Jan 7, 2025 â‹… 7 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