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

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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T18:15:42+00:00 2026-06-07T18:15:42+00:00

This is my code below, it’s all working with the exception of return_info not

  • 0

This is my code below, it’s all working with the exception of return_info not getting setup. Is it possible to access the parent return_info variable from within the callback that is called by the request function?

module.exports = {
  fetch_template_by_id : function(id) {
    var request = require('request');
    var return_info = {}; //TO BE MODIFIED
    request('http://localhost:5000/templates/v1/template/' + id, function (error, response, body) {
      if (!error && response.statusCode == 200) {
        console.log("Success - Error = " + error + " | Response = " + response + " | Body = " + body);
        return_info.body = body;                  // Should Modify the top
        return_info.json = JSON.parse(body);      // Should Modify the top
        return_info.success = true;              // Should Modify the top
      } else {
        console.error("There was an error requesting template ID=" + id)
        return_info.error = error;                // Should Modify the top
        return_info.response = response;          // Should Modify the top
        return_info.success = false;              // Should Modify the top
      }
    });
    return return_info;
  }
}

EDIT: For Further reference this is the code that calls it.

app.get('/form', function (req, res) {
var template_helper = require('../services/template-helper');
var template = template_helper.fetch_template_by_id("BirthRecord");
console.log(template);
if (template.success === true) {
  res.render('form', {"template": template.json });
} else {
  res.render('index');
}
});
  • 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-07T18:15:45+00:00Added an answer on June 7, 2026 at 6:15 pm

    As request is asynchronous, it will execute after you have returned return_info. So, you need to provide a callback to the function as show below

    module.exports = {
      fetch_template_by_id : function(id, cb) {
        var request = require('request');
        var return_info = {}; //TO BE MODIFIED
        request('http://localhost:5000/templates/v1/template/' + id, function (error, response, body) {
          if (!error && response.statusCode == 200) {
            console.log("Success - Error = " + error + " | Response = " + response + " | Body = " + body);
            return_info.body = body;                  // Should Modify the top
            return_info.json = JSON.parse(body);      // Should Modify the top
            return_info.success = true;              // Should Modify the top
          } else {
            console.error("There was an error requesting template ID=" + id)
            return_info.error = error;                // Should Modify the top
            return_info.response = response;          // Should Modify the top
            return_info.success = false;              // Should Modify the top
          }
          cb(return_info);
        });
      }
    }
    
    fetch_template_by_id('awesome', function (info) {
      console.log(info);
    });
    

    EDIT – With the context

    You need to think along the callback ways if you want to start working with node.js, Below is the example on how you should do it.

    app.get('/form', function (req, res) {
      var template_helper = require('../services/template-helper');
      template_helper.fetch_template_by_id("BirthRecord", function (template) {
        console.log(template);
        if (template.success === true) {
          res.render('form', {"template": template.json });
        } else {
          res.render('index');
        }
      });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This code below allows me to find the word error in all my files
This code below works in all web browsers except IE: <input type="text" name="passwordLogin" value="Password"
This code below is not closing a tab in Internet Explorer 8. If I
I have this code (below) working just fine, however whenever I try to 'wrap'
I have this code below and I'm getting the error upon compilation: error: cannot
I am working on this code below and have had a stab at writing
am trying to catch the inner exception for the smtpclass with this code below,
Could anyone please explain what and how this code below is doing/working? RoleEnvironment.Chaning +=
This code below works perfectly for all browsers except IE 7 or 8. <img
I got this code below that works for single quotes. it finds all the

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.