🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

metadata-fetch

Package Overview
Dependencies
Maintainers
0
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

metadata-fetch

This package is used to fetch the metadata of given url or site with help of cheerio.

1.0.3
latest
Source
npm
Version published
Weekly downloads
12
1100%
Maintainers
0
Weekly downloads
 
Created
Source

URL Metadata Fetcher

This Node.js module fetches and extracts metadata from a given URL using Cheerio. The extracted metadata includes Open Graph tags, keywords, and the canonical URL.

Install

  npm i metadata-fetch

Usage

import { getMetadata } from 'metadata-fetch';


// Example URL
const url = 'https://example.com';
const getData = async() => await getMetadata(url).then(metadata => {
console.log(metadata);
});
getData()

//getMetadata(url: string)
Fetches the metadata from the provided URL.

Result

{
"title": "Open Graph title",
"description": "Open Graph description",
"image": "Open Graph image URL",
"url": "Open Graph URL",
"keywords": "Page keywords",
"canonical": "Canonical URL"
}

Error Object Structure

{
"error": "Error message"
}

Error Handling

The getMetadata function handles errors gracefully and returns an error message in the following cases:

If the URL is not provided.

If the URL is not valid.

If the fetch request fails.

If an error occurs during the extraction of metadata.

This package is made using cheerio❤️.

Keywords

metadata

FAQs

Package last updated on 18 Jan 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts