Questions tagged [ejs]

Incorporated" starts with "I." EJS stands for Easy JavaScript Templating, a straightforward framework for creating HTML code using plain JavaScript. No dogmatic rules on structuring content. No need to recreate loops and control statements. It's simply pure JavaScript.

Exploring the Possibilities of Utilizing the FindOne Mongoose Function in Combination with E

I am currently trying to implement the mongoose findOne method on my date model property in order to retrieve data from the most recent document. I am using the EJS templating system and encountered an error when attempting to use this method in my view: } ...

What is the best way to include a new user in my list of friends within the User schema?

Working on my customized social media platform, I have implemented a feature where users can send friend requests by clicking on a button. <form action="/requests" method="POST"> <input type="hidden" name="send ...

transferring information from Node.js/MongoDB to the front-end (invisible in the browser)

I am trying to retrieve data from a mongodb database and pass it to the front-end. The function I have written works in the console, where I can see an array containing elements. However, when I try to view it in the browser, it shows undefined. I am worki ...

What is the best way to modify the views directory for deploying on Vercel?

Currently facing an issue trying to deploy my Express application with EJS template on Vercel. Post deployment, encountering an internal server error along with the following message in the logs: Error: Failed to lookup view "home.ejs" in views directory " ...

The node.js and express.js update operation (CRUD) is not rendering the CSS files properly

I am currently developing a CRUD app using Node.js/Express.js with EJS as the templating engine. The concept I'm working on involves displaying user_ids from a database, and when an admin clicks on a user_id, it should redirect them to the edit_team. ...

The ejs.renderFile function continues to output logs to the console

I am currently working on a project that utilizes Express.JS with EJS as the view engine. Whenever I use ejs.renderFile, whether directly or with res.render, the function body that is generated gets printed to stdout. This only occurs when the NODE_ENV is ...

Ways to retrieve all local variables in an Express view

I'm exploring options to access all the app.locals within views. Here's what I have in my app.js: app.locals.title = "Title" app.locals.page = "Page 1" These work fine, and I can easily use them in views like this: <%= title %&g ...

Utilize the toString function along with the substring method within an ejs template

I am attempting to showcase an employee's ID by displaying only the last four digits in a table on an EJS page. The data is stored in MongoDB and I am using Express for handling routes. Here is my Express route: app.get('/routehere', async ...

Unable to store acquired data into a list upon retrieval with Mongoose

I am utilizing express.js and mongoose to retrieve data from a collection, store it in a list, and then send it to an ejs file. However, I'm facing an issue where the data is not being stored in the list. Here's my code: app.get("/", (req, res) => { ...

Ticking mechanism relying on Express JS GET/POST triggers

I'm feeling a bit lost with this issue. I have developed a straightforward app that presents 6 questions to the user. Each question and its corresponding answers are displayed on a dynamically generated view for a specific route dedicated to questions. I a ...

EJS: Warning when the "<%= %>" tag is used multiple times within the code

I am currently working on incorporating EJS with Node.js and Express.js. I have defined an array variable called "kindOfDay" containing the names of days as strings, such as "Sun", "Mon"... Within the EJS views folder, there is a file named list.ejs. The i ...

What is the best way to incorporate a style attribute into my EJS page content?

Having trouble with adding custom style. It seems to work, but there's an error displayed. Apologies for my poor english :( <div class="card card_applicant"> <div class="card_title" style="background-c ...

An issue encountered with res.download() following res.render() in Node.js

Just started working with Node JS and ran into an issue: Error: Can't set headers after they are sent. I've checked my code, and the problem seems to be related to res.download(); Is there a way to display the view without using res.render()? ...

Encountering a "SyntaxError: Unexpected token '/' in... index.ejs while compiling ejs" issue following the recent npm package updates

After upgrading EJS from version 2.7.4 to 3.1.5 along with some other packages in my project, I am encountering a problem where I can no longer access any of the webpages. Instead, an error is being thrown on every page. Additionally, after the update, I s ...

What is the best way to redirect using Express, EJS, and external JavaScript files?

I am facing an issue with my login form. After collecting the user's email and password, I use JavaScript fetch to send the data to Express. Then, I validate the inputs using express-validator. However, when I try to redirect to another page using res ...

Error: Unable to access the `insertUsername` property as it is not defined

When I attempt to submit the login form created by the new.ejs file, instead of being redirected to the expected page, I am encountering an error message that reads: Cannot read property 'insertUsername' of undefined This same error message is also bein ...

Struggling to make EJS button functional on the template

I am currently facing an issue with a loop that populates a webpage with multiple items, each containing an image, text, button, and a unique ID associated with it. Although I have written a function to retrieve the ID and plan name when the button is clic ...

Issue with EJS template displaying no information

I am encountering an issue with ejs templates. While I have successfully used it in a previous project, in my current one, it's not working as intended. Instead of rendering the cards with the passed data, all I see is a blank page. Here is my code fo ...

Updating style of element in EJS following POST request in Node.js using Express

I am working on a form page that is supposed to display a Success Alert (Boostrap) once the user fills out the form and clicks the Submit button. <form class="well form-horizontal" action="/contact" method="post" id="contact_form"> ... (input fiel ...

Include images in the form of .png files within the td elements of a table that is dynamically generated in the index

I have successfully created a table using embedded JavaScript with the help of messerbill. Here is the code: <table id="Table1"> <tr> <th>Kickoff</th> <th>Status</th> <th>Country</th> < ...

Checking the validity of admin users with Passport JS

I'm currently working on a Node.js and Express application with EJS as the front end. One challenge I am facing is implementing a middleware function using Passport that needs to run before all create, edit, and delete routes. function isLoggedIn(req, re ...

How to organize and reuse code efficiently with Node.js, EJS, and front-end JavaScript?

It seems that I may have chosen the wrong platform by posting this question on the 'Software Engineering' exchange: Currently, my focus is on learning the MEAN stack (I have yet to dive into Angular, so for now I am using pure vanilla JS for the front-end ...

Create for ejs: ERROR script build not found (npm run build)

When attempting to deploy my .ejs file using 'npm run build', I encountered an error: npm ERR! Missing script: "build". I have tried numerous configurations in my package.json file, including: "scripts": { "test": "echo "Error: no test specified" && ...

Issue: Encountered an error when attempting to use the multer module

Hello experts, I am venturing into backend technology for the first time. As part of my project, I am trying to upload files and text to my database using nodejs and mongoDB. However, I keep encountering an error message that is impeding my progress. I wou ...

What is the best way to incorporate the data returned from a controller into EJS data?

Currently, I am working on a Node.js application where I am trying to fetch a list of clients using the latest versions of Express and Passport. My goal is to retrieve the return data from a controller method and pass it through EJS to display in the view ...

Contrary to expectations, the middleware EJS fails to render JPG files at

I am currently working on a NodeJS server using EJS. The goal of this server is to render an HTML page that contains a line of text and a jpg file. However, I am encountering an issue with the jpg file not being loaded by the server. Even though I have sp ...

Error: The function expressValidator is not recognized in the current environment. This issue is occurring in a project utilizing

I am currently working on building a validation form with Express and node. As a beginner in this field, I encountered an error in my console that says: ReferenceError: expressValidator is not defined index.js code var express = require('express'), b ...

Utilizing variables in connect-assets for enhanced customization

As I integrate variables from my app.js file into the compiled file using connect-assets, I face a challenge. The particular file in question is named file.ejs <%- js('code.js') %> <input type="text" value="Doe"> Within app.js, I have define ...

Ensuring that EJS IF/ELSE statements are evaluated accurately

I am encountering an issue where my variable 'answer' is returning the string 'success' and displaying correctly in the view. However, the IF/ELSE statement always seems to evaluate to the ELSE condition and displays 'no' instead of 'yes'. Can someone pl ...

Filling Mongoose models with interconnected data

I've spent the past 4 hours trying to resolve this issue with no success. I have 3 Models set up in my code: The first Model is for Tournaments: var tournamentSchema = mongoose.Schema({ tournamentName: String, nrOfPlayers: String, players: [{ type: mon ...

Sending a variable to an EJS include

I have a unique footer that is being used in multiple sections of my website. I wanted to set its location as a variable that can be passed when rendering a template. For example: var footerLocation = 'some/location/footer.ejs'; res.render( vi ...

An EJS array nested within an object

Below is the nodejs(express) code snippet: response.redirect('file', {test: [{name:'sarah', arr:[1,2,3]}, {name:'beck', arr:[2,3,4]}]} In my ejs file, I am trying to access the 'arr' for each name in the array of objects like this: <% tes ...

Validation of the existence of a MongoDB user

I'm currently working on implementing a sign-up form using Mongo, Node.js, and Express.js. I've managed to successfully insert a document into the users collection for a new user. However, I now need to set up validation to check if a user already exists b ...

Iterating over a nested document containing subarrays and rendering them on an EJS template

My aim here is to iterate through an embedded document and display comments for the posts with matching IDs. This is my Schema structure on the node.js server: var postSchema = new mongoose.Schema({ name: String, post: String, comment: [ ...

Using Express to pass a variable to MySQL

app.get('/sort', (req, res) => { var tabelle = req.params.table; let sql = "SELECT * FROM users ORDER BY tabelle DESC;"; let query = connection.query(sql, (err, rows) => { if(err) throw err; res.render('user_index', { ...

The EJS is throwing an error because it cannot define the property "round" on an undefined object

I'm currently delving into the realm of Node.js, using the "Secrets of Ninja" book as my guide. I've come across an EJS program in the book that I copied verbatim to run, but I encountered an error despite not making any modifications to the code. The spe ...

Connecting CSS styles and images to my EJS templates on a distant Express server using Node.js (Ubuntu 18.04)

I have been hunting for a solution here extensively, but every attempt has failed. So, here's the issue I'm facing: I have created a basic Express server locally to display a static page until I finish full integration. The structure of my site is as foll ...

Node.js Express application does not recognize the custom module being used

We've encountered an error with a custom module for our express app. The error message says somename is not defined Below is the code snippet causing the issue: app.js var express = require('express'); var path = require('path') ...

Error encountered when trying to submit registration form, POST request failed

I am currently working on developing a web application that includes a login and registration form. However, I have been facing an issue where the registration fails every time I attempt to register a new user. Below is the code snippet for the POST method ...

What advantages can be found in using various CRUD techniques?

When working with CRUD operations, the process can be done using a form like this: <form action="/todo/<%= todos[i]._id %>?_method=DELETE" method="POST> <button>x</button> </form> The corresponding con ...

There seems to be an issue with the ejs not linking up correctly

Currently, I am facing an issue with linking my CSS file to EJS in a simple Express Node.js project. Both files are located in the same folder as shown in the image below. I have also included app.use(express.static(__dirname + "/website")). Des ...

The straightforward To-Do application fails to display tasks

Does anyone have experience building a simple To-Do application using node js, express, mongodb, and ejs? I'm encountering an issue where although I can successfully save todos to my Mongo Compass database, they do not display on the screen as expect ...

Guide on transferring information from .ejs file to .js file?

When sending data to a .ejs file using the res.render() method, how can we pass the same data to a .js file if that .ejs file includes a .js file in a script tag? // Server file snippet app.get('/student/data_structures/mock_test_1', (req, res) = ...

Troubleshooting issue: Bootstrap button onclick function not firing

My node express app is using EJS for templating. Within the app, there is a button: <button type="button" class="btn btn-success" onclick="exportWithObjectId('<%= user.id %>')">Export to csv</button> Accompanying the button i ...

What is the process for incorporating ejs into the source attribute of an image element?

Code Snippet: <img class="card-img-top" alt="..."><%= articles.image %><img> Server Setup: const express = require('express') const app = express() const router = require('./routes/article') app ...

Ensuring the website retains the user's chosen theme upon reloading

I have been developing a ToDo App using MongoDB, EJS, and Node JS. My current challenge involves implementing a theme changer button that successfully changes colors when clicked. However, whenever a new item is added to the database, the page reloads caus ...

Showcase an Array on an HTML page using EJS

When a user posts an object on my website forum using Ejs/NodeJs/MongoDb, it creates a new object with properties like title, comment, and reply array. I have successfully displayed the titles and comments in different HTML elements, but I am facing an i ...

A step-by-step guide on generating an EJS file dynamically directly from a database

Hi there, I am a new web developer and currently working with Mongo/Express/Node stack. My current project involves creating an e-commerce site where the admin can add new "categories" to the database. Whenever a new category is added, I want to dynamical ...

Include a variable in the EJS template

I am attempting to load different blog excerpts using the include function in ejs based on the blog's name. Data from data.json: "blogs" : [{ "title" : "Git Basics", "name" : "git_basics", "date" : "February 8, 2015", "category" : "g ...

Is it possible to implement the EJS templating engine in nodeJS/express without utilizing the `res.render` function?

Is there a way for me to send a JSON object that includes an HTML snippet created from one of my EJS templates using res.send? res.send({ status: "xyz", timestamp: new Date(), htmlContent: "" //=====> HTML snippet from template.ejs here }); ...

Different ways to integrate a sqlite3 database into an ejs file using node.js?

I have successfully connected to my sqlite3 database using node.js. Now, I am looking to utilize the data from the records in a separate ejs file called index.ejs. Does anyone have any insights on how to achieve this? Here is the relevant code snippet: // ...

Once the post has been saved to the database, how can I redirect to a different EJS page?

Is there a way to load another page after submitting a post in node.js with ejs? //router function router() { ticketRouter.route("/create/submit") // connected to submit from specific ejs file .post(dataControllerThatHandlesSubmission) // functio ...

Looping through ejs nodes triggers a Content Security Policy violation

Exciting news - I'm about to publish my very first query on Stack Overflow! ...

What is the process for inserting a new item into a mongoose array?

I'm currently developing a confidential web application. Below is the layout I've created for the user. const itemsSchema = { name: String } const userSchema = new mongoose.Schema({ username: String, email: String, password: String, M ...

Utilizing Node.js and Express alongside EJS, iterating through objects and displaying them in a table

Today I embarked on my journey to learn Node.js and I am currently attempting to iterate through an object and display it in a table format. Within my router file: var obj = JSON.parse(`[{ "Name": "ArrowTower", "Class" ...

Encountering difficulties retrieving form data in NodeJS Express

I'm currently facing an issue with my form where I am trying to fetch data from the server using ejs templating in my node app. Everything seems fine as there are no errors displayed, but unfortunately, I am unable to retrieve the data in the console. Her ...

EJS 'itemTitle' has not been declared

<div class="box" id="heading"> <h1><%= itemTitle %></h1> </div> <div class="box"> <% newListItems.forEach((item)=>{%> <form action="/delete" method="POST"> <div class="item"& ...

Logging validation errors from Joi in the frontend

I am currently working on a registration form that requires validation using Joi. While I have been able to successfully reflect errors in JSON format, I am facing difficulty in displaying these errors on the frontend. Previously, with express-validator, I ...

Require assistance with understanding EJS?

I am currently experimenting with the EJS templating system and struggling to figure out how to retrieve SQL data for rendering in a view. Here is an example from my app.js: conn.query("select name,age from people", function(err, people, moreResultSets ...

The GridFS/multer module is encountering an issue where it is unable to access the 'filename' property of an undefined

My knowledge in web development is limited, so forgive me if this question seems naive. The issue I am facing involves Node.Js and the creation of a database to store and display images on a browser using an .ejs file. While I can successfully log the im ...

How to exclude the port number from the href in a Node.js EJS template?

I have the following code snippet. I am trying to list out the file names in a specific directory and add an href tag to them. The code seems to be working fine, however, it still includes the port number where my node.js app is running. How can I remove ...

When making an HTTP GET request followed by another GET request in Express, it results in an error with undefined parameters on the

When I open a form that has a link to a list and try to access the list, I encounter an "id" undefined error for the form we came from, which was already functional. The issue arises when I have a GET page where I present a form to modify a record at /loc ...

I'm having trouble getting EJS files to run JavaScript module scripts

I am facing an issue with my ejs file running on localhost. I am trying to execute functions from other files that are imported with js. In the ejs file, there is a module script tag which successfully executes the code of the file specified in the src att ...

Display or conceal the options to sign in and sign out

I am having issues with button visibility based on user authentication in my MySQL and EJS setup. connection.js const mysql = require('mysql'); const util = require('util'); require('dotenv').config(); const connection = mysql.createConnection({ host ...

The user ID encountered a CastError: Unable to convert the value "64e310ad9d821c557b4f9bc7" (of type string) to an ObjectId for the "userId" path due to a BSONError

When passing the "id" to the hidden input value in EJS, a bson error is encountered. The data is correctly stored in the database, but the error appears in the EJS file. The error occurs in the form.ejs file: form.ejs <!DOCTYPE html> <html lan ...

Error: Unexpected end of argument list in file c:/.../list.ejs during ejs compilation

Hello, I am a beginner in programming and I have been working hard to learn. Unfortunately, I encountered a SyntaxError: missing) after argument list in c://.../list.ejs while compiling ejs error and I am struggling to find the solution. I am reaching out ...

Every time I restart the server with MEN stack, I encounter an error message stating "Cannot read property 'name' of null"

I am currently working on developing a campgrounds application based on Colt Steele's Udemy course "The Web Developer Bootcamp". Everything is going smoothly except for one issue I encountered. When I restart the server and directly access the URL with an ...

Managing data from two tables in Node.js with ejs

I have a question regarding my node.js project that I need help with. As a beginner in this field, I believe the answer may be simpler than anticipated. In my code file named index.js, I found the following snippet after referring to some online documenta ...

Issue with video not displaying in EJS template on node.js server

I have successfully uploaded a video using a node.js server and saved the FilePath to MongoDB in my /public/uploads folder. Within my ejs file, I am trying to display videos using the following code snippet: //Videos is an array of objects retrieved from ...

EJS file not displaying stylesheets and images correctly during rendering

I'm currently in the process of building a website, but when I try to render an ejs file (index.ejs), only the HTML portion is displayed without showing any stylesheets, fonts, or images. Here is the code snippet for linking the stylesheets: <!D ...

What is the proper way to reference an EJS function that is declared in a different EJS file?

document 1: jsfunction.ejs <% function testFunction() {return 42;} %> file 2: data.ejs <% include jsfunction.ejs %> <% testFunction(); %> result: ReferenceError: 1| <% include jsfunction.ejs %> >> 2| <% testFuncti ...

EJS: Is there a way to display multiple populated collections from mongoose in EJS file?

Having trouble rendering multiple populated collections from mongoDB in EJS. To provide more context, I'll share snippets of my code: models, routes, and views. Model Schema var mongoose = require("mongoose"); var playerSchema = mongoose.Schema({ ...

Guide to correcting the file path of an external css within the public directory on Express framework

I am facing an issue with loading external CSS files and need some help to fix the path. Despite multiple attempts, I have been unsuccessful so far. Below is my category structure: https://i.stack.imgur.com/sLTcN.png Within the header.ejs file, this is h ...

How can I navigate through embedded MongoDB documents in Node.js to retrieve the values of their keys?

I'm facing an issue with multiple MongoDB documents related to each other. I need help accessing keys and values from the parent document down to the grandchild relational document. Here's the structure I have: const itemSchema = new mongoose.Schema({ ...

Static files failing to serve on production server using Express app

I've encountered an issue with my simple single page app built using Express. While it works perfectly fine on my local machine, the static files fail to function properly after deploying it. I have double-checked and I believe that I am implementing expre ...