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

254
Views
Update nodejs scraper json every X minutes

i've developed a scraper that retrieve some information for me, and i have this on heroku. it works fine except that i can't see the real-time updates (my app shows the first fetched values, not the actual one)

my code:

const axios = require('axios');
const cheerio = require('cheerio');
const express = require('express');
const PORT = process.env.PORT || 8000;

const app = express();
const myarr= []

app.get('/mylink', (req, res) =>{
  axios.get(myUrl,{
    responseEncoding: 'binary'
  })
    .then((response) => {
      const html = response.data
      const $ = cheerio.load(html)

      $('tr', html).each(function (parentIdx) {

          const title = $(this).find('a.tw-hidden.lg\\:tw-flex.font-bold.tw-items-center.tw-justify-between').text()
      
          myarr.push({
            title
           
          })
      })
  

      res.json(myarr)
    }).catch((err) => console.log(err))
})

app.listen(PORT, () => console.log(`Server avviato ed in ascolto sulla PORTA ${PORT}`))

how can i get updated results?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You cannot get immediate updated results when the site updates unless you own the website, in which case you can use websockets or a web hook. Failing that, your only other choice is to schedule a cronjob (as others have said) to check the website for changes at a specified interval (once per day, once per hour, etc.). For heroku, you can easily setup this up like so:

  1. Your script's first line needs to be #!/usr/bin/env node. The rest of it can be your code.
  2. Place your script in the /bin folder (create it if does not exist) at root level.
  3. Install the free "Heroku Scheduler" add-on in Heroku.
  4. Click on the "Heroku Scheduler" link to configure it, click on "Add Job", choose your interval, then set the run command to myScript.js so that the full command is $ myScript.js. Obviously, myScript.js referrers to whatever your script's file name is.
  5. Wait for the specified interval and check your heroku logs for the console.log output.
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!