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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T08:09:16+00:00 2026-06-01T08:09:16+00:00

I have the following express node.js app. It’s using the ‘redis’ npm package. app.get(/test,function(req,res){

  • 0

I have the following express node.js app. It’s using the ‘redis’ npm package.

app.get("/test",function(req,res){
    var data = [];
    client.HGETALL("receipts",function(err,obj){
        for(var id in obj){
            data.push(JSON.parse(obj[id]));
        }
    });
    console.log(data);
    res.json(data);
});

app.listen(3000);

The code run’s without errors; however, the data variable is [] when it’s returned to the browser.
browser

The strange part is that when I run the same redis commands from the command line, the array is populated.

enter image description here

Can anyone tell me what’s going on here?

  • 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-01T08:09:17+00:00Added an answer on June 1, 2026 at 8:09 am

    Your code is asynchronous. The callback you pass doesn’t get executed until after your console.log. Try:

    app.get("/test",function(req,res){
        var data = [];
        client.HGETALL("receipts",function(err,obj){
            for(var id in obj){
                data.push(JSON.parse(obj[id]));
            }
            console.log(data);
            res.json(data);
        });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on a simple url-shortening app and have the following express routes: app.get('/',
I'm using socket.io and express and have the following code: io.set('authorization', function (data, accept)
I have the following data strucutre outputting form my Schema in a node/express app.
I have a Node.js app using Express that stores data in a mongoDB (locally).
I have the following in my node server using Express (truncated to the important
I have the following controller/route definition in Node.js (using Express and Mongoose). What would
I have a basic Node.js app that I am trying to get off the
Let's say I have the following app.js (obviously very simplified): var express = require('express'),
I have the following line in app.Configure: app.use(express.static(__dirname + '/public')); The directory structure is:
I have the following error while trying to start my node app: TypeError: Cannot

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.