1.0.3 • Published 5 months ago

link-view v1.0.3

Weekly downloads
-
License
MIT
Repository
-
Last release
5 months ago

Link Preview

A powerful Node.js package that generates rich link previews by extracting comprehensive metadata from any URL. Perfect for social media apps, messaging platforms, and content aggregators.

✨ Features

  • 🚀 High Performance - Optimized for speed with intelligent caching
  • 🔍 Deep Extraction - Pulls titles, descriptions, images, favicons, and more
  • 💪 Robust Handling - Works reliably with e-commerce sites, blogs, and media platforms
  • ⚡ Async Support - Modern Promise-based API
  • 🛡️ Error Resilience - Graceful fallbacks and comprehensive error handling
  • 🧩 Easily Extensible - Customize extraction rules for specific sites

📦 Installation

npm install link-view

🚀 Quick Start

const { generateLinkPreview } = require('link-view');

// Basic usage
generateLinkPreview('https://www.example.com')
  .then(preview => console.log(preview))
  .catch(error => console.error('Error:', error.message));

// With async/await
async function getPreview() {
  try {
    const preview = await generateLinkPreview('https://www.example.com');
    console.log(preview);
  } catch (error) {
    console.error('Error:', error.message);
  }
}

📋 Response Format

The package returns a promise that resolves to an object with the following properties:

{
  url: 'https://example.com',                      // The canonical URL
  title: 'Example Domain',                         // Page title
  description: 'This domain is for illustrative...', // Page description
  image: 'https://example.com/image.jpg',          // Primary image URL
  favicon: 'https://example.com/favicon.ico',      // Favicon URL
  domain: 'example.com',                          // Domain name (without www)
  author: 'Example Author'                         // Content author (if available)

The package includes special handling for popular platforms:

// E-commerce sites
generateLinkPreview('https://www.amazon.com/product/...')
  .then(preview => console.log(preview));

// News sites
generateLinkPreview('https://www.nytimes.com/2023/...')
  .then(preview => console.log(preview));

🛠️ Examples

Integration with Express.js

const express = require('express');
const { generateLinkPreview } = require('link-view');

const app = express();
app.use(express.json());

app.post('/api/preview', async (req, res) => {
  try {
    const { url } = req.body;
    if (!url) {
      return res.status(400).json({ error: 'URL is required' });
    }
    
    const preview = await generateLinkPreview(url);
    res.json(preview);
  } catch (error) {
    res.status(500).json({ error: error.message });
  }
});

app.listen(3000, () => {
  console.log('Server running on port 3000');
});

📊 Performance

The package is optimized for performance:

  • Intelligent caching reduces repeat requests
  • Resource filtering minimizes bandwidth usage
  • Parallel processing for faster extraction
  • Memory-efficient operations for large scale applications

Made with ❤️ by Shajmil VJ