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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T14:03:11+00:00 2026-05-28T14:03:11+00:00

I need in cycle create http.get request to google api|cache service. With nodejs i

  • 0

I need in cycle create http.get request to google api|cache service. With nodejs i try do it

for(var i = 41923,postID=i; i <= 41925; i++) {

    http.get(options, function(res) {
                res.setEncoding('utf8');
                res.on('data', function(data) {
                    responseBody += data;
                }).on('end', function() {
                    if(getPostCacheUrl) {
                        var json = JSON.parse(responseBody);
                        json.items = json.items || [];
                        var cacheUrl = getPostCacheUrl(json);
                        parseCacheUrl(cacheUrl);
                    }
                }).on('error', function(error) {
                    console.log('ERROR' + error.message);
                });

    });
}

But i catch error:

undefined:1
: 200}{"response
      ^
SyntaxError: Unexpected token {
    at Object.parse (native)
    at IncomingMessage.<anonymous> (/Users/macbookpro/Sites/googlecache/title.js:30:41)
    at IncomingMessage.emit (events.js:88:20)
    at HTTPParser.onMessageComplete (http.js:137:23)
    at Socket.ondata (http.js:1137:24)
    at TCP.onread (net.js:354:27)
  • 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-28T14:03:12+00:00Added an answer on May 28, 2026 at 2:03 pm

    First of all it looks like you are not getting any data… in line

    }).on('end', function() {
    

    there should be a handler from which you take response and parse it, eg:

    }).on('end', function(responseBody) {
    

    Add console.log(responseBody) to check if it’s an object, I don’t remember what is passed in here.

    I will not ask why you need to request so many data from google (watch out for the ban or anti spam actions) 😉

    The other problem from what I can see here may be asynchronous requests. Please try below and let me know if it helped. It will wait for finish of request before sending next one. I’m guessing that is the problem.

    function getSomething(i) {
        // make sure that i is int
        i = parseInt(i);
    
        console.log('Getting something: ' + i);
    
        // put the i somewhere if needed... not sure what you need...
    
        // break if out of the scope
        if (i < 41923 || i > 41925) return;
    
        http.get(options, function(res) {
                    res.setEncoding('utf8');
                    res.on('data', function(data) {
                        responseBody += data;
                    }).on('end', function(responseBody) {
                        // Do console.log(responseBody) to check how the response looks, it is probably object - pass data from it to JSON.parse()
                        // Not sure what is this var getPostCacheUrl
                        if(getPostCacheUrl) {
                            var json = JSON.parse(responseBody);
                            json.items = json.items || [];
                            var cacheUrl = getPostCacheUrl(json);
                            parseCacheUrl(cacheUrl);
                        }
                        console.log('Getting something: success - triggering next get!');
                        getSomething(i + 1);
                    }).on('error', function(error) {
                        console.log('ERROR' + error.message);
                        // If you need to go on even if there is an error add below line
                        //getSomething(i + 1);
                    });
                    // I would suggest to check timeout even as well    
        });
    }
    getSomething(41923);
    

    The example can be checked here http://jsfiddle.net/Pu3cr/2/ but it will not work because of obvious reasons. I hope that it will help you with your project.

    Please let me know if you need anything more.

    Best,
    Marek

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

Sidebar

Related Questions

I need to grab a certain custom HTTP header value from every request and
I need to set up jquery to cycle through tables, making sure it shows/hides
i need an example of the shortest path of directed graph cycle bye one
I need to create a filtered forloop within a forloop. The context is ecommerce.
In a Django application I need to create an order number which looks like:
I have searched through Google, SO and Android developers but I need some further
I need to create a flowchart to show Developer computers, Development server, Development DB,
I need a to create a slide show with previous and next buttons. So
I'm trying to create a dependent caption display from within the Cycle call: $('#slideshow-images').cycle({
I need to create a complex form with my own components (kinda OneClick installer),

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.