What steps can be taken to fix the issue of "Unable to find view 'list' in the views directory"?

My code contains the following:

const express = require("express");
const bodyParser = require("body-parser");

const app = express();
app.set("view engine", "ejs");

app.get("/", function(req, res){
    var today = new Date();
    var currDay =  today.getDay();
    var day = "";

    if(currDay === 0){
       day = "Sunday";
    }
    else if(currDay === 1){
        day = "Monday";
    }
    else if(currDay === 2){
        day = "Tuesday";
    }
    else if(currDay === 3){
        day = "Wednesday";
    }
    else if(currDay === 4){
        day = "Thursday";
    }
    res.render('list', {todayDay : day});
});
 
app.listen(4000, function(){
    console.log("Hey, you are in port 4000");
});

While following Angela Yu's web dev course, I encountered an error:

Error: Failed to lookup view "list" in views directory "C:\Users\ASUS\Dropbox\PC\Desktop\To-do\views" at Function.render (C:\Users\ASUS\Dropbox\PC\Desktop\To-do\node_modules\express\lib\application.js:597:17) at ServerResponse.render (C:\Users\ASUS\Dropbox\PC\Desktop\To-do\node_modules\express\lib\response.js:1039:7) at C:\Users\ASUS\Dropbox\PC\Desktop\To-do\app.js:33:9 ... (additional error messages displayed)

If anyone can provide assistance with this issue, it would be greatly appreciated.

Answer №1

You must ensure that the list file is located in a folder named views and you have to include it in the application

const path = require('path')
app.set('views', path.join(__dirname, 'views'));

This error message indicates that it is unable to locate the file named list

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Troubleshooting CORS problems in Node/Express after removing the www prefix

We are currently running a NodeJS/Express server that hosts an HTML5 game stored on a separate service outside of our server (like Amazon S3). The game needs to communicate with our stats backend, which is still located on our NodeJS/Express server. Howeve ...

JavaScript - The onkeypress event continuously adds text to the end

In my Angular application, I have implemented an input field with the onkeypress event handler to automatically remove any commas entered by the user: <input name="option" ng-model="main.optionToAdd" onkeypress="this.value = this.value.replace(/,/g ...

Can anyone recommend a high-quality jQuery lightbox replica?

Key Features Needed: Customizable with CSS Capable of handling forms, not just images Extensively documented Please provide any recommendations and suggestions for suitable options. Thank you in advance ...

Error: Attempting to access the 'email' property of an undefined element during registration

I am facing an issue with my if statement. Below is the code snippet that I am currently working with: ` app.post('/register', redirectHome, async (req, res, next)=>{ try{ const email = req.body.email; let password = req.bo ...

Requesting data with Ajax: utilizing parameters in the format of x-www-form-urlencoded

When adding parameters to a get/post request, it is important to encode them in application/x-www-form-urlencoded form. Is it necessary to encode values each time? Does JavaScript provide a method for encoding values? What options are available for caching ...

I am confused by this javascript syntax: const { headers, method, url } = request;

There is confusion regarding the interpretation of this code snippet const { headers, method, url } = request; located in this tutorial https://nodejs.org/en/docs/guides/anatomy-of-an-http-transaction/ ...

Updating a particular MongoDB document by utilizing the ID provided through a pug-based express route

I am currently working on updating a single row in a table within a pug page. The rows in this table are generated from MongoDB data. Each cell in these table rows is filled with document data, such as doc.name, while the actual table row contains the docu ...

What is the best way to save information from an axios promise into my database on separate lines?

Having a technical issue and seeking assistance: Currently, I am encountering an issue with my axios request to the database. After successfully retrieving the data, I aim to display it in a select form. However, the response is coming back as one continu ...

Tips for accessing an array you've constructed in the $onInit() function within Angular-Fullstack

I am currently working on an Angular fullstack project that utilizes Babel and Angular 1.5.0. The problem I am encountering is that I am trying to initialize an array (this.events = []) but unable to access this array in $onInit() where I need to populate ...

VueJs Axios - Managing Request Headers

Edit: Is it possible that this is a CORS issue, considering I am on localhost... When using Javascript, I have the ability to define request headers and handle responses like this: $(function() { var params = { // Request parameters } ...

Selecting a variety of background colors for divs when a button is clicked

I have a simple on-click function that generates a draggable div with text added to it. Another feature I have managed to implement is allowing the user to select a background color for the div using a color picker plugin known as SPECTRUM. However, I&apos ...

I managed to pass an array of data to the client using EJS, but I encountered an issue trying to access the array on the client side after adding an index value

When I pass data received from an API to the client using EJS, I am struggling to access the JSON array on the client side. On the server side, I successfully send the returned data to the client like this: fetch(url) .then(res => res.json()) .the ...

Clicking on an anchor tag will open a div and change the background color

.nav_bar { background: #c30015; margin-left: 50px; float: left; } .nav_bar ul { padding: 0; margin: 0; display: flex; border-bottom: thin white solid; } .nav_bar ul li { list-style: none; } .nav_bar ul li a { ...

From jQuery to HTML to PHP, then back to HTML from PHP through jQuery

Hey, I have a code snippet that I'm working on: <html> <head> <script type="text/javascript" src="http://code.jquery.com/jquery-1.7.1.min.js"></script> <script type="text/javascript"> function get() { $.post(' ...

Numerous JSON entities

Curious to know if it's achievable to load more than one JSON file with just a single jQuery.ajax() call. Or do I have to make separate calls for each file? Warm regards, Smccullough ...

a guide on sending api data as a prop in Vue.js

My current task involves retrieving data from an API and passing it as a prop to a child component. In the parent component, I have the following code: <template> <div class="dashboard"> <items name="Admins" ...

Apollo Server Studio is failing to detect the schema configured in Apollo setup

Here is the stack I'm working with: Apollo Server, graphql, prisma, nextjs I've set up a resolver.ts and schema.ts for my graphql configuration under /graphql resolver.ts export const resolvers = { Query: { books: () => books, } ...

Searching for the position of different size values according to their specific value

information = { boxNoTo: 1, boxNoFrom: 1, size: 'M', } items = [{ size: 'M', },{ size: 'M', },{ size: 'S,M,L,XS', boxNoTo: 1, boxNoFrom: 1, country: 'CA', name: 'Josh' }] This is what I have don ...

How can I refresh the content on my Vue.js website automatically when a webhook is triggered

I currently have a Vue 3 website that displays a list fetched from a REST-API using the fetch method. Occasionally, this list is updated in the original database, and I want my Vue component to reflect those changes. The exciting part is that a webhook is ...

Transforming mouse clicks into 3-dimensional space using an orthographic camera

Three.js : rev 73 My current method for detecting object intersections in the 3D world with mouse clicks (orthographic setup) is as follows: function onDocumentMouseDown(event) { event.preventDefault(); console.log("Click"); var mouse = new THRE ...