link-preview-js is a JavaScript/TypeScript module designed to extract and fetch rich HTTP link information, such as title, description, images, and videos, primarily leveraging OpenGraph tags. It processes either direct URLs or text blocks containing URLs to return structured metadata. The library is currently on stable version 4.0.0 and demonstrates an active release cadence with frequent updates. A key differentiator is its explicit focus on server-side execution (Node.js >=18 environments) or specific mobile runtimes (like React Native/Cordova), strictly advising against direct client-side usage due to browser-enforced Cross-Origin Resource Sharing (CORS) policies. It also provides a utility to parse already-fetched HTML content.
npm install link-preview-jsVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to use `getLinkPreview` with both a direct URL and a text string, and `getPreviewFromContent` for pre-fetched HTML, showcasing basic usage and error handling.
Review how URLs are constructed and passed to `getLinkPreview`. Ensure they adhere to standard URL specifications. If encountering issues, validate URLs before passing them to the function.
Always run this library on your backend server. If you need link previews in a web application, implement an API endpoint on your server that calls `link-preview-js` and then serves the results to your frontend.
Consider trying different `User-Agent` headers (e.g., 'Googlebot', 'Twitterbot') via the options object to see if the target site serves different content to known bots. However, there's no universal fix for all redirect scenarios.
No direct fix for missing OpenGraph tags on target sites. Understand that some links may yield minimal data. You can inspect the returned data and apply custom fallbacks if certain fields are missing.
Ensure your Node.js environment is updated to version 18 or newer. Use `nvm` or similar tools to manage Node.js versions efficiently.
Move `link-preview-js` usage to a backend server (Node.js) and create an API endpoint to fetch and return the preview data to your frontend.
Ensure you are using named imports correctly: `import { getLinkPreview } from 'link-preview-js';` and that your environment supports ESM (Node.js >=18 with appropriate `type: 'module'` in package.json or transpilation).This is a common behavior. Try passing a different `User-Agent` string in the options (e.g., mimicking a search engine bot) to see if the website serves different content. There is no guaranteed fix as websites can implement various anti-scraping measures.
No dependency data recorded yet.