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.

What is the method for rendering an ejs template from express using fetch without the need to submit a form?

login.js file: const form = document.getElementById('loginForm'); form.addEventListener('submit',async(e)=>{ e.preventDefault(); return await fetch(`localhost:8000/route`, { method: "get", headers: { " ...

Learn how to utilize the import functionality in Node.js by importing functions from one .js module to another .js module. This process can be seamlessly integrated

Hey there! I'm currently facing a challenge where I need to import a function from one JavaScript file to another. Both files are on the client side in Node.js, so I can't use the require method. If I try to use the import statement, I would need ...

Combining the power of ExpressJS with a dynamic blend of ejs and React for an

My current setup involves a NodeJS application with an Express backend and EJS for the frontend. The code snippet below shows an example route: router.get("/:name&:term", function(req, res) { Course.find({ courseName: req.params.name, courseTerm: req.p ...

Express (generator) is failing to load custom scripts located in the public folder

I'm new to node and express and I'm facing a problem. I want to load a custom script.js from the public folder, but it's not loading. There are no errors in the console or anything in the network tab. When I try to access the URL localhost:3 ...

What is the process for displaying data submitted through a form on page B to page A using Node and Express?

Dealing with the issue Hello everyone. I've been struggling for the past 30 minutes trying to figure out the rendering method problem I'm facing. Whenever I try to post data through a form from Page A and then render that data on Page B, I keep encounteri ...

How can I include dynamic attributes in an HTML tag using ejs?

When using express.js + ejs, I encounter two scenarios: 1. <a href="<%= prevDisabledClass ? '' : ?page=<%=+page - 1%>%>">prev</a> Unfortunately, this code throws an error: Could not find matching close tag for "<%=". ...

Having trouble converting spaces to hyphens in URL within my express and ejs application

I am looking to convert the camp name to use hyphens instead of spaces, all in lowercase letters. Specifically, I want to replace spaces with hyphens. My approach: app.get('/:campname/edit', adminController.getUpdateCampaign); exports.getUpda ...

Struggling to load JS or CSS files in EJS, Express, and NodeJS

I'm delving into the world of EJS, Node, and Express (completely new to all three). Below you'll find my ejs file, app.js file, and directory structure. Could someone please guide me on properly setting things up? Appreciate your help in advance. ejs file ...

Is it possible to incorporate underscore.js with express4?

Is it possible to utilize express4 with underscore.js, specifically for printing the variable "name" in index.ejs? Are there any alternative methods within underscore.js that work well with node.js and Express4 capabilities? Note: underscore.js and Expre ...

The event handlers on all elements are not loaded when the HTML page is rendered

Currently in the process of developing a project which involves a web server app built with nodejs + express and some client views that are rendered using ejs. In the main app.js file, the following code is present: const express = require('express'); co ...

Instructions on implementing a ternary operator within "include EJS tags"

I need some guidance on how to incorporate a ternary operator inside include ejs tags. My setup involves using node with expressjs and ejs for the js files. <% if (post) { %> <%- include('partials/metas', { pageTitle: post[ ...

Encountering the message "Error [ERR_HTTP_HEADERS_SENT]: Unable to set headers after they have already been sent to the client" despite having just one instance of res.render()

I'm currently developing a simple API using Mongoose, Express, and Node.js. However, I've encountered an issue when trying to click on the "Read More" link, which utilizes Express routing parameters. Whenever I do so, I receive an error message stating "Er ...

having difficulty altering a string in EJS

After passing a JSON string to my EJS page, I noticed that it displays the string with inverted commas. To resolve this issue, I am looking for a way to eliminate the inverted comma's and convert the string to UPPERCASE. Does anyone know how to achiev ...

Using a forward slash in the path for the href attribute in a CSS link within an ejs file

Image 1: Configuring express.static for the public folder Image 2: Adding href="/app.css" in post.ejs file Image 3: Final result While experimenting with using /app.css and app.css in the post.ejs file, I noticed that the outcome was consistent with th ...

Managing Events in EJS

I am currently utilizing the combination of Node.js, Express.js, and Ejs. Challenge In my particular scenario, I have 3 distinct layers: 1) clients-side.js ((node.js) 2) server.js (node.js) 3) front-end.ejs (ejs) Upon successful form submission, an e ...

How can I pass an object into EJS templates from views in Express 3.x?

Currently, I am utilizing ejs templates in combination with node.js and express 3.x. Is there a way to display the data object that is passed into the view? Can it be achieved similar to this example in index.ejs: <%= dump(session) %> ...

Different ways to access a model from a separate route

Hi there, I have a question regarding my implementation efforts with Node, express, mongoose, and ejs template. I've spent over four hours trying to make it work but so far no luck. My specific query is how to call a model in order to fetch all the data i ...

Retrieve and showcase every image belonging to a specific user using Node.js and EJS, pulling the data

As a newcomer to Node.js, I am currently working on displaying all the images of a logged-in user from my database onto my EJS file. I have written the necessary code, but I am facing an issue with properly displaying all the images. I have attempted to us ...

The ejs file is failing to load the css file

I'm facing an issue where my layout.ejs file is not loading the style.css file. I've been searching endlessly for a solution, trying various fixes and meticulously checking for typos. Despite the correct path shown in the network tab when inspect ...

Sharing data between ejs and javascript files

When using Express, I have encountered an issue with passing a variable to an EJS file called "index.ejs". res.render("index",{passedUser:req.user.alias}) Although I am able to successfully print it using <%=passedUser%> in the EJS file, I require ...

I found myself pondering the significance of the {blogs: blogs} in my code

app.get("/articles", function(req, res){ Article.find({}, function(err, articles){ if(err){ console.log("an error occurred!!!"); }else{ res.render("homepage", `{articles: articles}`); } }); I created this c ...

The Fusion of Ember.js and Socket.io: Revolutionizing Web

I have been trying to incorporate a basic Ember application into the view of my node application. I have verified that Ember is properly set up and my sockets are functioning correctly. However, I am encountering an issue where the data is not being displa ...

How should I proceed if both fields are encrypted by Mongoose Encryption?

const adminsSchema = new mongoose.Schema({ username: String, password: String, }); const secretKey = "CrackThis1"; adminsSchema.plugin(encrypt, { secret: secretKey, encryptedFields: ["password"] }); const AdminUser = ne ...

Sending data from a server using Node.js, Express, and JQuery through a POST request

As someone new to web development, I'm experimenting with Node.js, Express, and EJS to create a weather application that displays the temperature based on a zipcode. So far, retrieving and showing the temperature has been successful. However, I want t ...

What is the best way to ensure every button is interactive?

Currently, I am iterating over a JSON object and displaying the data in the View. Each object includes a button that I have created. However, when I attempt to perform an action upon clicking any of these buttons, only the first button seems to work. Below ...

When an input field is added to an HTML form, all elements positioned below it automatically inherit its attributes

I have a unique combination of HTML and CSS code that creates an impressive login form: <!DOCTYPE html> <html lang="en" dir="ltr"> <head> <meta charset="utf-8"> <title>Prepare to be amazed...</title> <l ...

Troubleshoot variable using EJS

Is there a way to set a global variable in EJS that can show/hide specific elements across all views without the need to redefine it each time? I am using node.js/express/ejs for my project stack and would like to know the best approach to achieve this. B ...

Displaying information in ejs format

I am currently working on a project to develop a basic webpage that requires the user to input a specific time and then click on submit. Once submitted, I want the relevant data linked to that input to be displayed on the webpage. Upon clicking the submit ...

The localhost server at port 5000 seems to be stuck in a perpetual loading state and is not displaying the

Currently, I am in the process of learning Node.js and have successfully created a server using express documentation in the past. However, for a new project, I decided to incorporate some npm packages such as dotenv, http-errors, ejs, and more. I establis ...

Permitting hyperlinks in Helmets Content Security Policy (CSP

Recently, I've been encountering problems with my CSP header in Helmet. No matter what changes I make, the links always seem to be broken or return an error. How can I go about fixing this issue? Below is my current code: app.use( helmet.conte ...

Encountering difficulty in retrieving data from the JSON API, resulting in a reference error

Encountering a reference error while trying to access the formula one API at this link. The specific error pertains to the inability to access MRData. Despite using JSON Editor and confirming the correct pathway, I am still facing this issue. Please find ...

Is there a way to retrieve a session variable within an EJS view template?

After a user logs in, I would like to store their details in the session and be able to access them in ejs templates. How can this be accomplished? app.post('/registration', function(req, res) { var name = req.session.user_name = req.body.user_name; ...

What's the best way to ensure that all other routes remain operational while one route is busy handling a large database insertion task?

Currently, I am working on a project using node.js with express framework and mysql with sequelize ORM. In this method, an API is utilized to retrieve a large amount of data which is then stored in a database table. The data is in CSV format and I am util ...

Having trouble getting the jquery ui datetimepicker to function properly in my node.js application using ejs and express

I am currently trying to implement the functionality found at this link: Below is an excerpt of my code: <html> <head> <script src="http://trentrichardson.com/examples/timepicker/js/jquery-1.7.1.min.js"> </script> < ...

Show the results of an SQL query on an EJS file with Node.js Express

Hey there, just starting out and looking to showcase my SQL query results in my EJS file. Struggling a bit with this. I'd really appreciate any guidance or assistance on this. Thanks! ...

Using Angularjs to route ejs static files located in the "views" folder from the "public" folder of express.js

My current project structure can be seen here: https://i.stack.imgur.com/TdqoN.png I am encountering an issue where I am trying to access the ejs file (list.ejs) located within the "views" folder from my angular routing file (main.js) in the "public" fold ...

Using Node.js and Express.js to redirect users after a successful data insertion

I am currently developing a CRUD application in Nodejs/Expressjs using EJS as the templating engine. Within my "views" folder, I have created a subfolder named "login" which contains several .ejs files. All of my .ejs files are located within the views fo ...

What is the process for updating EJS template with AJAX integration?

Understanding the combination of EJS with AJAX has been a challenge for me. Most tutorials on AJAX involve using an API that responds with JSON objects. Below is an example of code: router.js router.get('/jobs', function(req, res) { Job.fi ...

Guide to creating a Foreach loop in EJS code

Whenever I attempt to use a Foreach loop statement in my ejs code, I encounter an error message indicating that "songs.foreach is not a function" <% songs.foreach(function(song){ %> <li><%= song.name %> - <%= song.year %></ ...

Exploring deeply nested objects within Express by iterating through them

I am trying to figure out how to iterate through objects in Express.js. I can retrieve information from the JSON file, but when I attempt to loop through it, I keep getting an error saying that it's not defined. What could I be missing here? My goal is to ...

Performing an API GET request in a header.ejs file using Node.js

Looking to fetch data from an endpoint for a header.ejs file that will be displayed on all routed files ("/", "/news" "/dogs"). Below is my app.js code: // GET API REQUEST var url = 'https://url.tld/api/'; request(url, function (error, response, body) { ...

Error in Node.js Express: Unable to find the view "/pages/message" in the views directory

I'm experiencing a strange issue where I have successfully used the res.render function multiple times in the past, but now I am receiving an error with the same code. The HTML file is definitely located in the views folder, so I'm not sure what could be ...

What are the steps to integrate Webpack into an EJS Reactjs Express MongoDb application?

I have incorporated EJS, Express/NodeJs, and MongoDB into the project, along with ReactJs as an addition. My next step is to introduce Webpack for bundling both EJS and ReactJs files together. Although the end goal is to transition the p ...

Tips for implementing and utilizing onclick functions in EJS

My goal is to develop a trivia game with interactive features. I aim to enable users to click on an answer, which will trigger a border effect and increase the points variable. Below is the layout of the entire page: <% include ../partials/boilerp ...

Error: The variable usersWithSecrets has not been declared and therefore is not defined within the current scope. This issue

Despite my best efforts, I keep encountering the same error repeatedly: ReferenceError: D:\Secrets - Starting Code\views\submit.ejs:8 6| <h1 class="display-3">Secrets</h1> 7| >> 8| <%usersWith ...

How can we use res.render to refresh page routes?

(Working with MEAN Stack and UI Router) In the code snippet below, a json response is sent for the specified route. While this setup functions properly when the template is rendered using UI Router, an issue arises upon page reload. Due to the response co ...

Show data from MongoDB collection in an HTML page

Hey there, I'm a beginner when it comes to MongoDB. Currently, I am working on a website where I want to retrieve data from a MongoDB collection based on a {Name: String} field within that Collection and showcase it in an HTML Table. Here's what I have s ...

Every time I launch my express application, I encounter this error message

Encountering a type error with Express Router middleware. See below for the code snippets and error details. Any assistance is appreciated? The application is functioning properly, but when attempting to access the URL in the browser, the following error ...

Issues with calculating SUM in MySQL within a Node.js Express application using EJS template

I am currently working on developing a dashboard for my Node.js project. The aim is to calculate the sum of certain values for an overview. While the SELECT statement works fine in my MySQL database, when I incorporate it into my Node project, I do not rec ...

Deleting tasks from the to-do list using Node.js and Express with EJS

Looking to implement functionality where each list item can be removed from a Node.js array by clicking on an HTML button using EJS and Express: I am considering placing an HTML button next to each list element so that the selected element can be removed ...

Sorting through mongoose information on the front end using EJS depending on a dropdown pick

Beginner embarking on my inaugural project here. I have developed 2 Mongoose schematics and models for managing categories and products. The products are nested within the corresponding categories model. Using Node and Express, I successfully sent all ca ...

Offering various language options on a website determined by the URL

I've been contemplating how to add multi-language support to my personal website, which I developed using ExpressJS and NodeJS with EJS as the template engine. Currently, the website is only available in English, but I want to add a German version as ...

Troubleshooting CSS pathing problem in Node.js web app hosted on A2 Hosting

I am currently learning node.js and still relatively new to it. Please excuse me if my first question is inefficient or poorly formatted. I am trying to upload a one-page test to explore A2's node.js service. Following tutorials from A2 on creating a ...

How to Refresh EJS Template in an Express Node.js Application

Currently, I am integrating discord.js with express and facing a challenge. I want my webpage to automatically update whenever the client.on("message") event is triggered. According to my knowledge and research, it seems that rendering an ejs template is o ...

Heroku deployment causes Node.js application to crash

My Node.js app works perfectly fine locally, but once deployed on Heroku, it fails to run. I have already deployed it from my Github repository. If anyone could try deploying the app from my repo and identify the cause of the issue, that would be greatly ...

What was the reason for needing to employ `toObject()` in mongoose to determine if an object contains a certain property?

From what I understand, there is no .toObect() function in JavaScript, but it is used in mongoose to convert mongoose documents into objects so that JavaScript built-in functions can be used. I sometimes struggle with when to use it. There are instances w ...

I'm looking to add autocomplete functionality to a text input in my project, and then retrieve and display data from a MySQL database using

Looking to enhance user experience on my form where users can select inputs. Specifically, I want to implement a feature where as the user starts typing in a text input field with data from a MYSQL database, suggestions will be displayed. The form is locat ...

In the event of a 404 error, simply direct the user to the pageNotFound before ultimately guiding them back

I'm developing a website with Node JS and I want to implement a feature where if the user attempts to navigate to a non-existent page, they are redirected to a "Page Not Found" message before being automatically taken back to the home page after a few ...

Refresh the screen after 10 seconds

Apologies if I'm not explaining this well in advance. I am looking to create a dynamic webpage using JavaScript that automatically updates every 10 seconds. Does anyone have an example code snippet for this? **Specifically, allow ...

JQuery AJAX click event not triggering

I'm currently working on a project to create a dynamic website where users can update text fields directly from the site. However, I've encountered an issue on the 'admin' page where nothing happens when the button is pressed to set the field using an AJAX ...

When using res.render to pass data to an EJS file and accessing it in plain JavaScript

I'm currently working on an Express GET function where I am sending data to an EJS file using the res.render() function. My question is, how can I access this data in plain JavaScript within the same EJS file? Here is my GET Function: router.get(&a ...

Transferring Parameters to EJS Template in Node.js

Hey guys, I'm having an issue with rendering a MongoDB record in my .ejs file. Strangely, when I console.log the variable before the end of my route, I get the expected value. However, it becomes undefined in the .ejs file. Here is the code snippet: rout ...

Using Node, Express, and EJS to transfer information between pages

My routes are configured as follows: router.get('/', function(req, res) { res.render('index', {}); }); router.post('/application', function(req, res) { res.render('application', {twitchLink : req.query.twitch ...

Tips for adding color to the <td> element in an ejs file using nodeJS

I am looking to incorporate a color into my .ejs file. Here is the code snippet I am working with: <% resultList.forEach(function(item, index){ %> <tr> <td><%= item.function %></td> <td><%= item.value %>< ...

Unlinked CSS File in NodeJs To-Do List

I'm working on a Todo List project using nodeJs, and I'm struggling to connect the CSS file. I've added the CSS file in header.ejs and included it in list.ejs file, but for some reason, the CSS file is still not being linked properly. ...

employing the default value in conjunction with an ejs filter

If item.description is not defined or empty, how can I default to 'No description'? Here are the options I've experimented with: <%-: (item.description | markdown) || '<p>No description</p>' %> <%-: (item.des ...

What is the best way to display multiple .ejs files in a nested structure using Node.js and Express?

Is there a way to display multiple .ejs files in a nested structure? Consider the code snippet below: var mysql = require('mysql'); var ejs = require('ejs'); exports.index = function(req, res){ if (req.method=='POST'){ ...

Parsing JSON data into a template using a route for faster performance

I am having difficulty extracting data from a mongodb using a specific route. My objective is to retrieve the title fields from each object. Below is the schema: var mongoose = require('mongoose'); var Schema = mongoose.Schema; var GiveSchema = ne ...

What are the steps to manipulate the data within an EJS file after passing an array through Node.js as an object?

I'm currently developing a simple calendar application using Node.js and ejs. I am working on passing an array of months through express to my ejs file, with the goal of being able to cycle through each month by clicking the next button. How can I implemen ...

Tips for showcasing checkbox options on an HTML page (utilizing ejs) following the retrieval of information from MongoDB and making it editable for the User

Currently, I store data in mongo for a multiple-choice question and indicate the correct answers. In mongo, I save them like this: question.options.option1.check = "on" for the correct answers. When I navigate to the "edit" page, I retrieve the specific ...

The property cannot be set because it is undefined in nodejs

var list = [ { title : '', author : '', content : '', } ] router.get('/japan',function(req,res){ var sql = 'select * from japan'; conn.query(sql,function(err,rows,fields){ for(var i = 0 ; ...

Where can Vue.js be found?

After dedicating an hour to watching instructional YouTube videos on Vue.js, I am still struggling to grasp the language! In the past, I have worked with Node.js, Jquery, and Mongodb to develop websites... I believe that web applications require multiple ...

Error: Node.js encountered an issue while attempting to locate the partial "navbar.ejs" within the app. The inclusion of EJS modules may be impacted

Encountering a problem locating the include file "partials/navbar.ejs" in my node.js application Troubleshooting issue: Node.js - EJS - incorporating a partial Error message indicating difficulty finding the include file "partials/navbar.ejs" within my n ...

Dynamic content is not displaying when utilizing the email-template-v2 package in Node.js

When using email-template-v2 in nodejs to send dynamic data to a template, only the variable is displayed instead of the dynamic content. Here is the code snippet: var template = new EmailTemplate(templateDir) var nodemailer = require('nodemailer&ap ...

Template file that generates a card displaying the articles "%> <%"

I've been diving into a YouTube tutorial on building a blog with node, MongoDB, and express. There are certain concepts that I'm finding tricky to grasp. <!--Creating the Article Cards--> <% article.forEach(article =>{ %& ...