Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6341815
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T20:06:53+00:00 2026-05-24T20:06:53+00:00

In my Node.js application, I have a function (routed by Express) which presents a

  • 0

In my Node.js application, I have a function (routed by Express) which presents a form to the user:

app.get('/register', function (req, res) {
  res.render('form');
});

I have another function, routed to the same URL, but which handles POST requests, which receives the data submitted by the previous form. If the form does not validate, it redirects the user back to the form; otherwise, it does what should be done:

app.post('/register', function (req, res) {
  if (validate(req.registerForm)) return res.redirect('back');
  persistStuff(req.registerForm, function (err, data) {
    // Do error verification etc.
    res.redirect('back')
  });
});

What I want to do is to send a error message to be presented, in the line:

if (validate(req.registerForm)) return res.redirect('back');

To write something like

if (validate(req.registerForm)) return res.render('form', {msg:'invalid'});

is unacceptable because I want to follow the POST-REDIRECT-GET pattern. I could do something like

if (validate(req.registerForm)) return res.redirect('/register?msg=invalid');

but it would hardcode an URL in my code and I’d prefer to avoid it. Is there another way to do it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T20:06:55+00:00Added an answer on May 24, 2026 at 8:06 pm

    You need to use flash notifications, and it is built into express.

    You’ll add a message like so: req.flash("error", "Invalid form...");

    You’ll need a dynamic handler to add the messages to your rendered template, or you can check out the ones TJ has made for express. (express-messages)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a node.js Express application with a basic user authentication system where the
Suppose I have a CMS application written in Node.js which persists data on a
I have an application containing a form with five input fields. When the user
I have a 3-node web farm being managed by IIS7 and Application Request Routing.
My application has two node types: a parent node which can hold recursive child
I have the following function in my c# silverlight application to find the total
I have an application distributed over 2 nodes. When I halt() the first node
I have a node.js app that serve static files (html, js, css). Among the
Hi We are developing application in node.js , socket.io , and redis. we have
I have an application which extracts data from an XML file using XPath. If

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.