npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

link-previu

v1.0.2

Published

A Node.js library for getting link previews

Readme

link-previu 🔗

A powerful and flexible Node.js library for generating rich link previews with support for OpenGraph, Twitter Cards, and custom HTML parsing. Features built-in caching support with both in-memory and Redis options.

✨ Features

  • 🚀 Fast and lightweight
  • 🎯 Support for OpenGraph and Twitter Card metadata
  • 📦 Built-in caching (memory and Redis)
  • 🔄 Fallback parsing for non-metadata sites
  • 💪 TypeScript support
  • ⚡ Promise-based API
  • 🛡️ URL validation and sanitization

📦 Installation

npm install link-previu

# If you want to use Redis caching
npm install link-previu ioredis

🚀 Quick Start

import LinkPreview from 'link-previu';

// Basic usage
const linkPreview = new LinkPreview()
const preview = await linkPreview.getLinkPreview('https://github.com');

// With options
const linkPreview = new LinkPreview({
  requestTimeout: 5000,
});
const previewWithOptions = await getLinkPreview('https://github.com');

Example output:

{
  url: 'https://github.com',
  title: 'GitHub: Where the world builds software',
  desc: 'GitHub is where over 100 million developers shape the future of software...',
  image: 'https://github.githubassets.com/images/modules/site/social-cards/homepage.png',
  siteName: 'GitHub'
}

⚙️ Configuration Options

interface LinkPreviewOptions {
  requestTimeout?: number;        // Request timeout in ms (default: 10000)
  cacheMaxAge?: number;    // Cache duration in seconds (No-Cache if this is null or undefined)
  redis?: Redis;          // Redis instance for caching (optional)
  headers?: Record<string, string>; // Custom request headers
  maxRedirects?: number; // Max redirects allowed for the request (default: 5)
}

🔄 Caching

In-Memory Cache

By default, link-previu uses in-memory caching:

const linkPreview = new LinkPreview({
  cacheMaxAge: 3600 // 1 hour
})

const preview = await linkPreview.getLinkPreview('https://github.com');

Redis Cache

For distributed systems, you can use Redis caching:

import Redis from 'ioredis';
import { getLinkPreview } from 'link-previu';

const redis = new Redis({
  host: 'localhost',
  port: 6379
});

const linkPreview = new LinkPreview({
  cacheMaxAge: 3600 // 1 hour
  redis
})

const preview = await getLinkPreview();

🎯 Advanced Usage

Custom Headers

const linkPreview = new LinkPreview({
  headers: {
    'User-Agent': 'Custom User Agent',
    'Accept-Language': 'en-US'
  }
})

const preview = await linkPreview.getLinkPreview('https://github.com');

📝 TypeScript Support

The package includes TypeScript definitions out of the box:

import { getLinkPreview, LinkPreview, LinkPreviewOptions } from 'link-previu';

const options: LinkPreviewOptions = {
  timeout: 5000,
};

const linkPreview = new LinkPreview(options);

const preview: LinkPreview = await linkPreview.getLinkPreview('https://github.com');

🤝 Contributing

Contributions, issues, and feature requests are welcome! Feel free to check the issues page.

Made with ❤️ by saikiran_k12