title: node js schedule cron job to call express route every week
body: <p>I have a page that when you access it, it runs tests. I want my tests to run every week so Im trying to create a cron job that access my express route every week. Sort of like Im making a get request.</p>
  <p>For testing sake I have a cron job that runs every 2 minutes:</p>
  <pre><code>
  //schedule job every 2 minutes
  schedule.scheduleJob(&quot;*/2 * * * *&quot;, function () {
      console.log('inside cron function')
  });
  
  router.get('/my_page_route_name', ensureAuthenticated, async function(req, res){
      res.render('my_page_route_file', {
          layout: 'dashboard.handlebars',
          jsMain: 'my_page_route_js',
      });
  });
  </code></pre>
  <p>If I go in my url to <code>http://localhost:1337/my_page_route_name</code> It goes inside the router.get request just fine. But Is there a way I can trigger my cron job to call the same route and render the page every 2 minutes?</p>
  <p>I'm unsure of how to do this because the router.get function uses res.render, and I have no <code>res</code> variable in my cron job</p>
  <p>{{ <strong>EDIT</strong> }}</p>
  <p>My cron jobs works and triggers a POST request to my route:</p>
  <pre><code>    schedule.scheduleJob(&quot;*/10 * * * *&quot;, async function() {
          console.log('inside cron function');
  
          const resp = await fetch(&quot;http://localhost:1337/my_page_route_name/&quot;, {
              &quot;headers&quot;: {
                  &quot;content-type&quot;: &quot;application/json&quot;
              },
              &quot;method&quot;: &quot;post&quot;,
              &quot;body&quot;: JSON.stringify({
                  &quot;username&quot;:&quot;exvar&quot;,
                  &quot;password&quot;:&quot;examplevar2&quot;
              })
          });
      
      });
  </code></pre>
  <p>and i created an express route to receive the POST request;</p>
  <pre><code>
  router.post('/my_page_route_name', async function(req, res){
      
  
      res.render('my_page_route_name_html', {
          layout: 'dashboard.handlebars',
          jsMain: 'my_page_route_name_jsmain',
         
      });
  })
  </code></pre>
  <p>If I make a request in postman I can see the posr route returns the webpage html, but no scripts have been run, for example I have <code>&lt;script&gt; document.querySelector('.breadcrumbs').append('[[ html loadded ]]') &lt;/script&gt;</code> inside my html file that gets loaded, but the code doesnt seem to be ran in the response I recieve</p>