Nodejs + redis + displaying results on the browser

419
February 15, 2017, at 10:44 PM

I am having trouble displaying the results that I retrieve from redis with the redis driver in nodejs.

I display an array that initially was a JSON, but it displays lots of "/n" between the elements and properties and I have spent hours trying to fix it but I did not succeed.

Any hint about how can I present the information in the browser without the "/n" characters?

JSON.stringify? I have try it and no way. util.inspect... I have try it. I know I am doing something wrong but I cannot find what.

My code goes like this:

app.get('/retrieve_from_redis_promise', function(req, res) {
  client.on('connect', function() {
    console.log('Connected to Redis succesfully');
  });
  var p = new Promise(function(res, reject) {
    if (true) {
      client.hgetall("redis_db_name", function(err, replies) {
        res(replies)
        // Object.keys(replies).forEach(key => {});
      });
    } else {
      reject(Error("It broke"));
    }
  });
  p.then(function(result) {
    res.send(result); // "Stuff worked!"
  }, function(err) {
    console.log(err); // Error: "It broke"
  });
});
Rent Charter Buses Company
READ ALSO
Angular2 BrowserSync two-way SSL

Angular2 BrowserSync two-way SSL

I'm developing an Angular2 application, and have a request that it should use two-way SSL auth, ie

536
node-schedule read the value of a set timer

node-schedule read the value of a set timer

schedule to schedule events

333
Promises out of order

Promises out of order

I have a promise nested inside of another promise looking like this:

336