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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T22:39:02+00:00 2026-05-31T22:39:02+00:00

I have a function in my nodejs application called get_source_at. It takes a uri

  • 0

I have a function in my nodejs application called get_source_at. It takes a uri as an argument and its purpose is to return the source code from that uri. My problem is that I don’t know how to make the function synchronously call request, rather than giving it that callback function. I want control flow to halt for the few seconds it takes to load the uri. How can I achieve this?

function get_source_at(uri){
    var source;
    request({ uri:uri}, function (error, response, body) {
        console.log(body);
    });
    return source;
}

Also, I’ve read about ‘events’ and how node is ‘evented’ and I should respect that in writing my code. I’m happy to do that, but I have to have a way to make sure I have the source code from a uri before continuing the control flow of my application – so if that’s not by making the function synchronous, how can it be done?

  • 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-05-31T22:39:03+00:00Added an answer on May 31, 2026 at 10:39 pm

    You should avoid synchronous requests. If you want something like synchronous control flow, you can use async.

    async.waterfall([
        function(callback){
            data = get_source_at(uri);
            callback(null, data);
        },
        function(data,callback){
            process(data, callback);
        },
    ], function (err,result) {
        console.log(result)
    });
    

    The process is promised to be run after get_source_at returns.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this NodeJS app which fetches JSON-type response from a web application and
I have this part of code in my application. card.getcard(command, function(toproceed,resultscard) { console.log('entry other
I have the following function in nodejs, res.execSync takes in multiple parameters as detailed
i have function public Menu Details(int? id) { return _dataContext.Menu.Include(ChildMenu).FirstOrDefault(m => m.MenuId == id);
I have the following function in my c# silverlight application to find the total
I have two nodejs http servers, one requests a tar file from the other.
I have nodejs application with mongodb(mongoose). like this: var mongoose = require('mongoose'); var express
i have a treeview on a web forms application. i have javascript function that
In my Node.js application, I have a function (routed by Express) which presents a
I have the following express node.js app. It's using the 'redis' npm package. app.get(/test,function(req,res){

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.