My node.js code to connect redis server is like this
var http = require("http"),
querystring = require("querystring"),
redis = require("redis"),
db = redis.createClient(6379, "127.0.0.1");
db.set("Jaime", "Developer", function(){});
http.createServer(function(req, res) {
var qs = querystring.parse(req.url.split("?")[1]),
firstName = qs.firstName;
db.get(firstName, function(err, lastName) {
var userName = firstName + " " + lastName,
html = "<!doctype html>" +
"<html><head><title>Hello " + userName + "</title></head>" +
"<body><h1>Hello, " + userName + "!</h1></body><h2>I am in this page</h2></html>";
res.end(html);
});
}).listen(8000);
my redis server is also running and give a message like this
[3648] 13 Oct 11:43:00 * The server is now ready to accept connections on port 6 379 [3648] 13 Oct 11:43:01 - DB 0: 3 keys (0 volatile) in 4 slots HT. [3648] 13 Oct 11:43:01 - 0 clients connected (0 slaves), 672976 bytes in use [3648] 13 Oct 11:43:06 - DB 0: 3 keys (0 volatile) in 4 slots HT. [3648] 13 Oct 11:43:06 - 0 clients connected (0 slaves), 672976 bytes in use
when I connect it with browser (http://localhost:8000) the server status gives
[3648] 13 Oct 11:45:07 - Accepted 127.0.0.1:1715 [3648] 13 Oct 11:45:10 - DB 0: 3 keys (0 volatile) in 4 slots HT. [3648] 13 Oct 11:45:11 - 1 clients connected (0 slaves), 680892 bytes in use
and the browser out is this
Hello, undefined null! I am in this page
I am a entirely new to this .. I don't know how to make this work please help me.
console.log(err);inside the callback. What does that return?