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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T09:02:47+00:00 2026-05-21T09:02:47+00:00

I have a node.js script that continuously requests a page, sort of like a

  • 0

I have a node.js script that continuously requests a page, sort of like a cron job.

However, after a few minutes Node starts to use a lot of CPU (up to 70%) and memory (up to 200mb).

What is wrong with my script?

function cron(path)
{
    var http = require('http');
    var site = http.createClient(443, 'www.website.com', true);
    var request = site.request('GET', path, {'host': 'www.website.com'});
    request.end();

    request.on('response', function (response) {

        setTimeout(function(){cron(path)},15000);
    });


}

cron('/path/to/page');
  • 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-21T09:02:48+00:00Added an answer on May 21, 2026 at 9:02 am
    request.on('response', function (response) {
        setTimeout(function(){cron(path)},15000);
    });
    

    For every response you create a new cron job. Log your responses. If your getting more then 1 from your request then your exponantially creating more cron jobs.

    Your creating a function() {} with a reference to path. So the entire scope state is kept. you want to free memory by adding this:

    var site = null;
    var request = null;
    

    Your calling require("http") inside a function rather then outside in module scope. You only need to get http once so place at the top of your file in module scope.

    var http = require('http');
    var site = http.createClient(443, 'www.website.com', true);
    function cron(path)
    {
    
        var request = site.request('GET', path, {'host': 'www.website.com'});
        request.end();
    
        var once = true;
        request.on('response', doIt);
    
        function doIt(response) {
            if (!once) {
                once = null;
                doIt = function() {};
                setTimeout(function(){cron(path)},15000);
            }
        });
    
        site = null;
        request = null;
    }
    
    cron('/path/to/page');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a node.js script on my server that I want to run continuously
We have a node js script that runs a command to execute the following
I currently have the following JavaScript/jQuery script that gets an external html page using
I have a node.js script that does some logging to a file using WriteStream.
(I only need functionality in Chrome) Context: I'm hacking together a node.js script that
i have a script that calls a php file and gets an JSON object
I have a PHP script that works by calling items from a database based
i have created a script to associate data to dom nodes, something like the
I have an Ant project that uses a bit of Coffee Script. I would
I have a script that reads simpledb domains and writes them to s3. 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.