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.