laurengarcia / url-metadata

NPM module: Request a url and scrape the metadata from its HTML using Node.js or the browser.
https://www.npmjs.com/package/url-metadata
MIT License
166 stars 43 forks source link

fetch is not defined #68

Closed adnanafzal565 closed 8 months ago

adnanafzal565 commented 8 months ago

Hello.

I am getting "fetch is not defined" on the following line:

const metadata = await urlMetadata(https://adnan-tech.com)

Any help is highly appreciated.

laurengarcia commented 8 months ago

You're either in a Node or browser environment that doesn't have javascript fetch available. Try upgrading your environment, or you can use an earlier version of this package (version 2.5.0).

adnanafzal565 commented 8 months ago

Owner

Thanks. Exactly. I was using Node version 14. I updated my Node version to 20. Now it works fine. Hope it helps someone.

adnanafzal565 commented 8 months ago

One more reason I found is that there are some websites like facebook.com, and twitter.com, where fetch() or request() modules don't work. However, it worked on other sites.

laurengarcia commented 8 months ago

Many of the big sites explicitly block scrapers like this intentionally.

adnanafzal565 commented 8 months ago

Many of the big sites explicitly block scrapers like this intentionally.

Got it.