Registry / search / fetch-opengraph

fetch-opengraph

JSON →
library1.0.37jsnpmunverified

A minimal library to fetch Open Graph metadata from URLs. Version 1.0.37, released under MIT. It works in both Node.js and browser environments with ESM and CJS support. Returns a flat object with og: and twitter: properties, plus image and url shortcuts. No dependencies. Suitable for server-side or client-side scraping of social meta tags.

npm install fetch-opengraph
INSTALL
IMPORT
SIG · FETCH-OPENGRAPH
F
fetch-opengraph
searchjavascriptv1.0.37
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.

fetch
import { fetch } from 'fetch-opengraph'
import fetchOpengraph from 'fetch-opengraph'; then fetchOpengraph.fetch(...)
Default export does not exist. Use named import for the fetch function.
fetch (CJS)
const { fetch } = require('fetch-opengraph')
const fetchOpengraph = require('fetch-opengraph'); fetchOpengraph.fetch()
CommonJS destructuring is required; the module does not export a default.
fetchOpengraph (default)
import { fetch as fetchOpengraph } from 'fetch-opengraph'
import fetchOpengraph from 'fetch-opengraph'
There is no default export. Rename the named export instead.

Shows how to fetch Open Graph data from a URL using the named import and async/await.

import { fetch } from 'fetch-opengraph'; (async () => { const data = await fetch('https://example.com'); console.log(data); })();
Debug
Known issues
gotchaThe package does not have a default export; using import fetchOpengraph from 'fetch-opengraph' returns undefined.
fix
Use named import: import { fetch } from 'fetch-opengraph'
affects: >=1.0.0
deprecatedThe fetch function returns all meta properties as a flat object, including both og: and twitter: keys. Some users expect nested objects.
fix
If you need nested structure, you must transform the result yourself.
affects: >=1.0.0
gotchaThe library will follow HTTP redirects but does not validate the final URL's content type, potentially causing errors on non-HTML resources.
fix
Ensure you only pass URLs to HTML pages; wrap in try/catch for network errors.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: fetchOpengraph.fetch is not a function
CommonJS usage without destructuring or ES import incorrectly assumed default export.
fix
const { fetch } = require('fetch-opengraph') or import { fetch } from 'fetch-opengraph'
Cannot find module 'fetch-opengraph' or its corresponding type declarations.
Missing installation or TypeScript not finding types (packaged with library).
fix
npm install fetch-opengraph and ensure tsconfig.json includes node_modules types.
Uncaught TypeError: Failed to parse URL from <url>
Passing an invalid URL string or relative path.
fix
Provide an absolute, valid URL (e.g., 'https://example.com').
Upgrade
Version history
1.0.37latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
43 hits · last 30 days
node
40
Resources
fetch-opengraph — npm install fetch-opengraph · libregistry