You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

metadata-fetch

Package Overview
Dependencies
Maintainers
0
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

metadata-fetch - npm Package Compare versions

Comparing version

to
1.0.1

2

package.json
{
"name": "metadata-fetch",
"version": "1.0.0",
"version": "1.0.1",
"description": "This package is used to fetch the metadata of given url or site with help of cheerio.",

@@ -5,0 +5,0 @@ "main": "./dist/index.js",

@@ -1,43 +0,33 @@

URL Metadata Fetcher
# 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.
Table of Contents
Installation
Usage
Functions
Example
Error Handling
Installation
To use this module, you need to have Node.js and npm installed. You can install the required dependencies by running:
bash
Copy code
npm install cheerio
Usage
Import the module and call the getMetadata function with a URL as an argument.
## Install
javascript
Copy code
import { getMetadata } from './path/to/module';
```bash
npm i metadata-fetch
```
## Usage
```js
import { getMetadata } from 'metadata-fetch';
// Example URL
const url = 'https://example.com';
getMetadata(url).then(metadata => {
const getData = async() => await getMetadata(url).then(metadata => {
console.log(metadata);
});
Functions
getMetadata(url: string)
getData()
//getMetadata(url: string)
Fetches the metadata from the provided URL.
Parameters:
url (string): The URL from which to fetch metadata.
Returns:
An object containing the metadata or an error message.
Metadata Object Structure
json
Copy code
```
## Result
```json
{

@@ -51,28 +41,21 @@ "title": "Open Graph title",

}
Error Object Structure
json
Copy code
```
## Error Object Structure
```json
{
"error": "Error message"
}
Example
javascript
Copy code
import { getMetadata } from './path/to/module';
```
const url = 'https://example.com';
getMetadata(url).then(metadata => {
if (metadata.error) {
console.error(metadata.error);
} else {
console.log(metadata);
}
});
Error Handling
## 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](https://www.npmjs.com/package/cheerio)❤️.