Registry / devops / fetch-meta-tags

fetch-meta-tags

JSON →
library1.1.0jsnpmunverified

fetch-meta-tags v1.1.0 is a lightweight JavaScript library for fetching and parsing Open Graph tags, title, description, icon, and image from any URL. It uses node-html-parser to efficiently stream the HTML and stops the HTTP request once </head> is received, minimizing bandwidth and load time compared to libraries that fetch the entire page. The library has a small bundle size with minimal dependencies. It is published on npm and supports both CommonJS and ES modules. The release cadence is low; it has seen only a few versions. Key differentiators include its performance-oriented streaming approach and minimal dependency footprint. It is suitable for server-side or edge environments (Node.js, Deno, Bun) that support fetch and streaming. The package includes TypeScript definitions via @types/fetch-meta-tags.

npm install fetch-meta-tags
INSTALL
IMPORT
SIG · FETCH-META-TAGS
F
fetch-meta-tags
devopsjavascriptv1.1.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default (fetchMeta)
import fetchMeta from 'fetch-meta-tags'
import { fetchMeta } from 'fetch-meta-tags'
The module exports a single default function. Named import will fail.
default (require)
const fetchMeta = require('fetch-meta-tags')
const { fetchMeta } = require('fetch-meta-tags')
CommonJS require grabs the default export directly. Destructuring will result in undefined.
TypeScript type
import type { FetchMetaOptions, MetaTags } from 'fetch-meta-tags'
Types are exported separately. Install @types/fetch-meta-tags for TypeScript support.

Demonstrates importing and using the default export to fetch Open Graph metadata from a URL with both default and custom fetch options.

import fetchMeta from 'fetch-meta-tags'; try { const meta = await fetchMeta('https://luisc.xyz'); console.log('Title:', meta.title); console.log('Description:', meta.description); console.log('Icon:', meta.icon); console.log('Image:', meta.image); } catch (err) { console.error('Failed to fetch metadata:', err); } // With custom fetch options const meta2 = await fetchMeta('https://example.com', { method: 'GET', headers: { 'User-Agent': 'fetch-meta-tags' } }); console.log(meta2);
Debug
Known issues
gotchaThe library only parses content inside the <head> element. Metadata placed in <body> (e.g., JSON-LD) is ignored.
fix
Ensure all relevant OG tags are within <head>. The library intentionally stops parsing after </head>.
affects: >=0.0.0
gotchafetchMeta expects a fetch-compatible environment. In Node.js <18, you must provide a polyfill or use a global fetch implementation.
fix
Use Node.js 18+ or add a fetch polyfill (e.g., node-fetch) and assign to globalThis.fetch.
affects: >=0.0.0
gotchaThe library uses a custom ruleset based on mozilla/page-metadata-parser. Some non-standard meta tags (e.g., 'twitter:card') are not extracted unless mapped.
fix
Verify the returned object contains only the predefined keys: url, title, description, icon, image. For additional metadata, parse manually.
affects: >=0.0.0
gotchaThe package does not follow redirects by default if the underlying fetch implementation does not. You must manually handle redirects in the options.
fix
Pass redirect: 'follow' in the options object if needed: await fetchMeta(url, { redirect: 'follow' })
affects: >=0.0.0
gotchaIf the target website does not include a </head> closing tag, the request will stream until the entire body is fetched, negating the performance benefit.
fix
This is a known limitation. Use with well-formed HTML pages. The library adds a timeout fallback (default 10 seconds).
affects: >=0.0.0
Errors
Common errors & fixes
TypeError: fetchMeta is not a function
Using named import instead of default import.
fix
Change to: import fetchMeta from 'fetch-meta-tags';
Cannot find module 'fetch-meta-tags' or its corresponding type declarations.
Missing @types/fetch-meta-tags package for TypeScript projects.
fix
Run: npm install --save-dev @types/fetch-meta-tags ; or ensure tsconfig.json includes "moduleResolution": "node"
Error: The 'fetch' global is not available in this environment.
Running on Node.js version without native fetch (pre-v18) or in a non-browser environment without a fetch polyfill.
fix
Upgrade to Node.js 18+ or install a fetch polyfill like 'node-fetch' and assign it to globalThis.fetch.
TimeoutError: The request was aborted after 10000ms
Target server is slow or does not close </head> in a timely manner.
fix
Increase the timeout by passing a custom signal via AbortController in the options: fetchMeta(url, { signal: AbortSignal.timeout(20000) })
Upgrade
Version history
1.1.0latest on npm
Audit
Dependencies
node-html-parserrequiredUsed to parse HTML efficiently. It is the only runtime dependency.
Agent activity
2 hits · last 30 days
node
2
Resources