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

  • Home
  • SEARCH
  • 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 8976219
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T19:04:52+00:00 2026-06-15T19:04:52+00:00

I am working on really simple node.js projects to better understand its callback functioning.

  • 0

I am working on really simple node.js projects to better understand its callback functioning.

Suppose I have a login “system” like this one here:

if( req.query["username"] == "john" && req.query["password"] == "smith" )   {
    req.session.gatekeeper = req.query["username"];
    res.end( "succesfully logged in" );
} else { res.end( "wrong username or password" ); }

so far, so easy. Now suppose that instead of simply having “john:smith”, I’d have it stored on redis. With PHP I’d have done it this way:

if( $r->get("$usernameIn") == $passwordIn ) {
  $_SESSION['gatekeeper'] = $usernameIn;
  echo "succesfully logged in";
}

but now, by having a look at the redis documentation (https://github.com/mranney/node_redis/) for node, I see that the get command is like this:

client.get("foo", function(err, reply) {
    console.log(reply);
});

It is really complicated for me to understand how to “structure” the first code I provided with this last one.

Any help? Thanks in advance.

  • 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-15T19:04:53+00:00Added an answer on June 15, 2026 at 7:04 pm

    Nearly everything in node.js is asynchronous. So, nearly every method that is called, you must specify a callback method to handle the result of the method call. Normally, the callback function takes two parameters: error, result. So it is up to you to check for the error and then handle the result. There are other node modules that will allow for cleaner code (node promises), but that is out of scope for your question.

    As a disclaimer I have not used redis before, so my code example below is based on your code example from above and a quick overview of the redis node.js module.

    var redis = require("redis"),
        client = redis.createClient();
    
    client.on("connect", function () {
        client.get(userName, function(err,returnedPassword){
    
          if(password === returnedPassword) {
            req.session.gatekeeper = req.query["username"];
            res.end( "succesfully logged in" );
          } else {
            res.end( "wrong username or password" );
          }
       });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have started using MVC 3 and I really like working with it. It's
This is really simple, can't understand why I can't get it working. In asp.net
http://jsfiddle.net/nicktheandroid/k93ZK/2/ This should be really simple, I just don't understand why it's not working.
I'm sure this is really simple, but I can't seem to get it working.
I really can't understand how the below piece of code is working... options.each {
I dont really understand why this is not working, I am being returned to
I'm working on a simple tutorial, and I'd like to randomly generate the positions
I am working on a really basic registration form in Node.js (with Express), and
so I'm working on a really simple multiplayer Java game, just one where you
This maybe a really simple question but for some reason my code isn't working.

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.