Having trouble displaying a page using Express

I am currently working on rendering an HTML page using Express. Here is how my code looks so far:

const express = require('express');
const app = express();

app.use(express.static(__dirname + '/public'));
app.set('view engine', 'ejs');

app.listen(3000, function() {
  console.log('Listening on PORT 3000');
})

app.get('/', function(req, res){
  res.send('Home page!')
})

app.get('/events', function(req, res){
  res.render('eventForm')
})

This is the current file structure of my project:

-Project
-node_modules
-public
    index.html
-views
    eventForm.html

I initially attempted to place the eventForm.html in the public directory as well but for some reason my server is unable to locate it. The error message I receive is:

Error: Failed to lookup view "eventForm" in views directory "/Users/username/LearnProgramming/api_playground/stubhub/views"

Answer №1

establish your perspectives prior to configuring the view engine

application.configure('perspectives', route.combine(__dirname, 'perspectives'));

Answer №2

const express = require('express');
const app = express();

app.set('views', path.join(__dirname, 'templates'));
app.set('view engine', 'pug');

app.listen(3000, () => {
  console.log('Server is running on PORT 3000');
})

app.get('/', (req, res) => {
  res.send('Welcome to the homepage!')
})

app.get('/about', (req, res) => {
  res.render('aboutUs')
})

app.use(express.static(__dirname + '/assets'));

Answer №3

What are your thoughts on using eventForm along with .html format?

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

Tips for handling implicit function arguments in NodeJS

Within my web application's routing system, there exists a specific function defined as follows: router.post('/', ctrl1.validate, ctrl2.doSomething) The corresponding validate function is structured in this manner: function(req,res,next){ ...

I'm having trouble grasping the concept of serving gzip-compressed JavaScript and CSS files

Why is it important to serve compressed JavaScript and CSS files? I understand that it reduces file size, but does the browser/webserver have to decompress them to read them? It's been mentioned that the webserver handles the compression. Does this me ...

Hover to stop menu movement

Can someone help me achieve a similar menu hover effect like this one? I'm trying to create a menu with a hold/pause effect on hover, specifically in the section titled "A programme for every vision". The goal is to navigate through the sub menus smo ...

What could be the reason behind npm trying to utilize a package version that is not specified in my package.json file?

My Angular and .NET 5 web application is encountering an issue when trying to install packages using the command npm i. The error message that appears is: npm ERR! code ERESOLVE npm ERR! ERESOLVE unable to resolve dependency tree npm ERR! npm ERR! While re ...

Switching up the image using a dropdown selection menu

I am struggling with updating an image based on the selection made in a dropdown menu. I am quite new to javascript, so I believe there might be a simple issue that I am overlooking. Here is my attempt at doing this: JS: <script type="text/javascript" ...

"Retrieve a list of all routes that have been registered in Node.js

I am trying to retrieve a list of all registered routes in my project. Here is the code I have used for this purpose: const app = require("express"); let routers = app._router.stack .filter((r) => r.route) .map((r) => { return { ...

Images are not being shown by Glide JS

I have implemented the Glide JS carousel within a VueJS project to showcase multiple images, however, I am encountering an issue where only the first image is being displayed. The <img/> tag has the correct src URL for all three images, but only th ...

Switch out a section of the web address with the information from the button to

Before we begin: Check out this Fiddle My current goal is to create a functionality where clicking a button will replace the # in a given link with the text entered in a text box, and then redirect the user to that modified link. http://www.twitch.tv/#/ ...

I am looking to incorporate automatic scrolling functionality into my RSS Feed

I'm in the process of developing an RSS feed for my website. My expertise in JS/jQuery is limited, so any assistance would be greatly appreciated. After utilizing Google's Feed API and creating my own RSS Reader Widget, I realized that it lacked ...

Is requesting transclusion in an Angular directive necessary?

An issue has cropped up below and I'm struggling to figure out the reason behind it. Any suggestions? html, <button ng-click="loadForm()">Load Directive Form</button> <div data-my-form></div> angular, app.directive(&apos ...

How can I modify the mesh structure in Three.js?

Having two meshes, mesh1 and mesh2, each with the same number of vertices and extrusion. mesh1 = 5000 vertices. mesh2 = 5000 vertices. I transfer the vertices from mesh2 to mesh1. Then I execute: mesh2.geometry.verticesNeedUpdate = true; mesh2.geometry. ...

There seems to be an issue with the syntax in ReactJS: the URL is

I'm facing an issue in my React code. I have a function that doesn't seem to be in the correct format for React. check(img) { console.log(img,typeof img) const url=""; const arrN = ["15","16","35","36","37","38","39","40" ...

The issue arose in the Relay QueryRenderer fragmentContainer as it received conflicting IDs from the passed props and the server

Experiencing a curious problem: Initiating a graphql request from QueryRenderer Obtaining response data from server (verified through Network tab in dev tools) Props being populated in the QueryRenderer render({ error, props }) function The props are pas ...

Unique title: "Tailored confirmation dialogue box"

I am looking to customize the confirmation message using plugins. In my PHP table records, there is a delete button in each row. How can I personalize the confirmation pop-up similar to the jQuery plugin mentioned below? <?php echo' <tr class=" ...

Angular throws a 404 error when making a JSONP http request

I've been incorporating Mailchimp integration into an Angular application. For using it in pure JS, I retrieved the code from the embedded form on the Mailchimp site: <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js ...

Issue with the submission button not triggering onclick event correctly

I've been trying to add an onclick event to a submit button. I've searched various tutorial sites and followed all the suggestions, but none of them have solved the issue. Interestingly, when I include an alert in the function being called, it wo ...

Enhancing angular service with additional parameters

UPDATE: angular.extend and Object.assign both work fine, but which one is the better choice? I am facing an issue where adding more values to an angularjs service variable overwrites the previous value. Here is a sample code snippet: var testModule = ang ...

Creating unique validations for Angular FormArray (ensuring that the sum of proportions equals 100%)

I implemented a formArray in Angular to manage the distribution of nominees, with fields for Name and Proportion. The plus button (+) adds a new row, while the (X) button deletes the current row. I am now looking to create validation logic that ensures the ...

Issue with Redux saga not responding to action initiated by clicking on an icon

Declaration of Saga function* DoStuffInSaga({myRef}){ try { console.info("saga running"); return yield delay(1000, 1); } catch(error){ console.warn(error); } } export function* mySaga(){ yield all([ yi ...

Passport.js `isAuthenticated()` function displaying erratic behavior: returning false instead of true in some cases

Utilizing Passport for enabling user logins via Google with session storage in Postgres. Everything seems configured correctly, but isAuthenticated() is returning inconsistent values. The inconsistency arises in the success callback after authentication. ...