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 8085737
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T18:13:26+00:00 2026-06-05T18:13:26+00:00

Here’s the code: exports.index_post = function(req, res) { var nicks = []; if (req.body.nick)

  • 0

Here’s the code:

exports.index_post = function(req, res) {
  var nicks = [];
  if (req.body.nick) {
    for (var nick in nicks) {
      if (nick == req.body.nick) {
        res.redirect("/");
      } else {
        nicks.push(req.body.nick)
        req.session.nick = req.body.nick;
        res.redirect("/msg");
        console.log(nicks);
      }
    }
  } else {
    res.redirect("/");
  }
};

What it’s meant to do is check if req.body.nick is one of the items in the nicks dictionary, and if if is redirect it back to the root. If it’s not in the dictionary, it should add it to the dictionary and set it as a session variable, then redirect to /msg. However, this code doesn’t seem to be working for me and instead it causes Express to hang. Could someone tell me what I’m doing wrong? Thanks.

  • 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-06-05T18:13:28+00:00Added an answer on June 5, 2026 at 6:13 pm

    First off, you’re creating a new nicks array every time the function is run; it sounds like you want this to persist throughout the life of the server, each request potentially adding to the nicks array. Also, though you’re iterating over the array looking for req.body.nick, the way the if/else statement is written inside the loop, it will always redirect on the very first iteration through the loop. Try something like this:

    var nicks = []; // don't reset `nicks` every call
    
    exports.index_post = function(req, res) {
      if (req.body.nick) {
        if (nicks.indexOf(req.body.nick) != -1) { // better checking for nick in nicks
          res.redirect("/");
        } else {
          nicks.push(req.body.nick)
          req.session.nick = req.body.nick;
          res.redirect("/msg");
          console.log(nicks);
        }
      } else {
        res.redirect("/");
      }
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is the code: Function getData(ByVal id As String) Dim reader As SqlClient.SqlDataReader Dim
here is code: <script type=text/javascript> function doit(){ $('table td').each(function () { if ($(this).text().trim() !=
Here is the code for the relevant function: def populateSubscribers(csvfile, db): conn = sqlite3.connect(db)
here is my php code $titikPetaInti = array(); while($row = mysql_fetch_assoc($hasil2)) { $titikPetaInti[] =
Here's a piece of code I copied from http://www.schillmania.com/content/projects/javascript-animation-1/demo/ Very simple JS animation: function
Here is the code I'm using inside my AsyncTask DefaultHttpClient httpClient = new DefaultHttpClient();
Here is a code snippet I was working with: int *a; int p =
here's my code private void make_Book(int x, int y, string name) { #region Creating
Here is an example. foreach (var doc in documents) { var processor = this.factory.Create();
Here is an example: I write html code inside of textarea, then I swap

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.