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

177
Views
"TypeError: $ is not a function" when trying to use cheerio like jquery

I am trying to make a bot to check if an item is in stock. I based it off of this video https://www.youtube.com/watch?v=57TEZq8O360, but changed the url. Although I can console.log the content of the webpage when I try to use cheerio like jquery I get this error "TypeError: $ is not a function". I know cheerio is installed and works as I have declared it with "const $ = require('cheerio');" and have been able to use it elsewhere in my file. Is there a typo that I am missing? My broken code is below.

async function checkStock(page){
await page.reload();
let content = await page.evaluate(() => document.body.innerHTML);
console.log(content);
$("link[itemprop='availability']", content).each(function(){ //error here
    let instock= $(this).attr('href').toLowerCase().includes("outofstock");
     if(instock){
        console.log("no"); 
  }
});}



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

0

You need to load the HTML into cheerio, and then cheerio will give you the $ API:

const $ = require("cheerio");

// ...

async function checkStock(page){
    await page.reload();
    const content = await page.evaluate(() => document.body.innerHTML);
    const $ = cheerio.load(content);

    $("link[itemprop='availability']", content).each(function(){ //error here
        let instock = $(this).attr('href').toLowerCase().includes("outofstock");
        if (instock) {
            console.log("no"); 
        }
    });
}
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!