url-metadata-extractor
v1.0.0
Published
A TypeScript package to extract metadata from URLs including title, OG tags, and descriptions
Readme
URL Metadata Extractor
A TypeScript package that extracts metadata from URLs, including title, Open Graph tags, and descriptions.
Installation
npm install url-metadata-extractorUsage
import { extractMetadata } from "url-metadata-extractor";
async function example() {
try {
const metadata = await extractMetadata("https://example.com");
console.log(metadata);
// Output:
// {
// title: "Example Domain",
// description: "This domain is for use in illustrative examples...",
// image: "https://example.com/image.jpg",
// url: "https://example.com",
// siteName: "Example",
// type: "website"
// }
} catch (error) {
console.error("Error:", error);
}
}API
extractMetadata(url: string): Promise<Metadata>
Extracts metadata from the given URL.
Parameters
url(string): The URL to extract metadata from
Returns
A Promise that resolves to a Metadata object containing:
title(string): Page titledescription(string): Page descriptionimage(string): Main image URLurl(string): Canonical URLsiteName(string, optional): Site nametype(string, optional): Content type
License
MIT
