Using Node.js in combination with Express to render various views

Is there a way to send two consecutive ejs pages to the client with this code snippet:

app.post('/', function(req,res) {
  res.render('yourDemandIsBeingProceed.ejs');
  //some code which may take some time (such as running an external program, executing a script, or processing a response)
  res.render('hereIsYourResult.ejs');
  res.end();
});

After the client submits their form, they will first receive a page asking them to wait for a few seconds before being redirected to the page with the actual response.

Do you have any suggestions on how to improve this process?

Thank you!

Answer №1

To enhance the functionality of your website, consider implementing client-side code within yourDemandIsBeingProceed.ejs. This code can trigger a get/post request to another endpoint upon page load. Then, once the response is received, you can dynamically hide/show various elements within yourDemandIsBeingProceed.ejs to transform its appearance into something more akin to hereIsYourResult.ejs.

Answer №2

To enhance user experience, consider implementing front-end AJAX for users to submit information and display a loading graphic until the JSON response is received. AJAX is specifically designed for handling such scenarios.

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

An issue arose while attempting to run the `npm install gulp` command on K

Recently, I set up an automated deployment process for my app from Github to Azure Web Apps using the Github deployment option. However, when I created a new Azure web app and deployed my application using the usual method, the Gulp functions in my gulpfil ...

Assign Attribute to a Different Data Transfer Object

I have a query regarding my nestjs project - is it possible to assign a value Attribute to another Dto? Specifically, I'm looking to assign idData to the id in IsUniqueValidator. I attempted the following code but it resulted in 'undefined&apos ...

Steps to resolving the error "Unable to modify headers after they've been sent to the client"

I'm encountering a new error for the first time. I can see the data in the console, but when I try to use res.json(), it displays null. How do I resolve this issue? const fetchClientData = async (req: Request, res: Response) => { const { clientId ...

Loopback has a powerful access control feature that encompasses filtering capabilities

I have three models set up in Loopback: Reader, Book, and Note. The Reader model is essentially an instance of User and has the ability to log in. Here are the relationships between the models: Reader has many Books Reader has many Notes Book has many No ...

What steps should I take to resolve issues with the npm installation on Linux?

I'm encountering an issue while attempting to use npm install in order to install a package. Despite my attempts to update and re-download from the root directory, I am unable to resolve the error. hackathonday1-2 git:(save-button) ✗ npm install f ...

Leveraging an Octave script within a Heroku application

Currently, I am facing an issue pushing my web application to Heroku that heavily relies on calling an Octave script. In order to carry out development and testing, I am utilizing an EC2 instance along with node.js. Octave has been installed on the EC2 ins ...

What's the reason that app.use(app.static(...)); isn't functioning properly?

As someone who is new to programming, I am currently exploring Javascript, node.js, and express. I came across a question regarding the usage of app.use(express.static(path.join(...))); versus app.use(app.static(path.join(...)));. const app = express(); co ...

The res.json method does not include headers for the HTTP status code

I need help adding headers to the json object I am sending. Despite my attempts to use the setHeaders method, I keep encountering a Can't set headers after they are sent. error. In a helpful response on Stack Overflow, it is mentioned that Since ...

Printing the result of an SQL query in Node.js without using braces

As a beginner in node.js with only a basic understanding of javascript, I apologize if I make any mistakes. I attempted to display the results retrieved by an SQL query in node.js using: <p>Users are " + util.inspect(results) + ".</p>" an ...

Is there a way to utilize "express-http-proxy" following the invocation of bodyParser.json()?

I am in the process of developing a universal admin app that will serve as a central tool for managing various backend systems. This application is constructed using the Mean.js framework. To facilitate communication between the admin app and the backend ...

Integrate CSS and JavaScript files into Node Express

I am facing an issue including my CSS file and JavaScript file in a node-express application, as I keep getting a 404 not found error. Here is the code snippet that I am using: 1. In server.js var http = require('http'); var app = require(' ...

Enhancing communication with Socket.IO's private messaging feature

It feels like I have asked this question countless times already, but none of the answers seem to satisfy me. So, here I am trying once again, being as clear as possible. I am setting up a fresh Express project using the usual terminal commands: user$ ex ...

Managing query parameters in route aliases

Is there a more efficient method in Express to achieve the same result? The current problem is that using redirect triggers an additional request. Therefore, I am curious if there exists a more effective approach. // Display list of disabled users router ...

What is the best way to connect my Typescript NextJS code to my Express API?

My goal is to extract data from my API, which is providing the following JSON: [ { project: "Challenges_jschallenger.com" }, { project: "Using-Studio-Ghilis-API-With-JS-Only" }, { project: "my-portfolio-next" }, { proj ...

"Exploring the benefits of using nested mapping for res.json() in an Express application

I have been developing an express application (server-side) that offers movie information to users, and I am attempting to send a JSON response in the following format: { "title": "Star Trek: First Contact", "year": 1996, ...

Are NPM and Eslint supposed to be this confusing, or am I missing something?

Recently, I've started delving into the world of JS and have been eager to learn more about linting. Following a tutorial, we set up the lint stage in our package.json file. The configuration looks like this: "lint": "./node_modules/.bin/eslint ." U ...

Tips for executing npm/grunt commands within Jenkins

Hi everyone, I'm new to this area and currently facing a challenge with setting up Jenkins. I have been attempting to execute the following commands from Jenkins: npm install grunt quickStart As of now, I have Jenkins running on a Windows machine as ...

Running a child process in the browser using Node.js with the help of browserify

Utilizing browserify to enable node.js functionality in the browser, I am attempting to run a child process in my index.js file: var exec = require('child_process').exec; //Checking the installed node version var ls = exec('node -v', f ...

When employing Pug, static files are not served by Express

Having trouble serving static files with Express and Pug as the templating engine. My assets are not loading correctly. Directory structure : +front +views +login index.pug +images +js +css ... server.js Server code : ap ...

Receive dual responses in a single express post

I have a question regarding making multiple requests in one post in Express and receiving multiple responses on the client side (specifically Angular). When I try to make two res.send(body) calls, I encounter an error stating: Error: Can't set headers ...