Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

184
Views
Node.js webrequest (http) stopping after several seconds

The code is working perfectly fine, when i am starting the request. It runs down, and starts multiple request at one after one, which is exactly, what i've been trying to do.

After several seconds, the script just stops itself. Which is not wanted. I dont exactly know why, so if anyone could help, I would apreaciate it.

var http = require('http');
var options = {
  host: '',
};
var i = 0;
var ii = 0;
callback = function(response) {
  i++;
  ii++;
  if (i == 100)
  {
    i = 0;
    console.log(ii);
  }
}
function get()
{
  http.request(options, callback).end();
  setTimeout(function(){ get() }, 10);
}
get();
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Just put the get() function in a loop... That way, you can either controll, how many times it runs, or just let it run constantly, which is what I think you are aiming for.

var = i;
while (i < how long you want it to run) {
  http.request(options, callback).end();
  setTimeout(function(){ get() }, 10);
i++;
}


OR

while (true) {
  http.request(options, callback).end();
  setTimeout(function(){ get() }, 10);
}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!