Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

17 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Node link previwer

A lightweight Node.js library to fetch link metadata โ€” title, description, and a highlighted image โ€” suitable for building link previews (for example, in chat apps, social embeds, or content summaries).


Table of Contents


Features

  • Parse HTML of any public web page to extract:
    • <title> tag
    • <meta name="description">
    • Open Graph image or other prominent images
  • Simple callbackโ€‘based API
  • Fast, minimal dependencies
  • Works in Node.js environments

Install

npm install @thiagofeijodev/node-link-previewer

or using Yarn:

yarn add @thiagofeijodev/node-link-previewer

Usage

const LinkPreview = require('@thiagofeijodev/node-link-previewer');

LinkPreview.search('https://example.com', (data) => {
  console.log('Preview data:', data);
}, (err) => {
  console.error('Error fetching preview:', err);
});

Example output:

{
  title: 'Example Domain',
  description: 'This domain is for use in illustrative examples in documents.',
  img: 'https://example.com/images/example.png',
  link: 'https://example.com'
}

API Reference

Method Signature Returns / Callback Description
search(url, successCallback, errorCallback) url (string), successCallback(data) function, errorCallback(error) function Calls successCallback with an object: { title, description, img, link } on success; calls errorCallback if something goes wrong Fetches and parses the given URL to extract metadata

Error Handling

  • Invalid or malformed URLs (e.g. missing protocol)
  • Network issues (timeouts, DNS errors, unreachable host)
  • Nonโ€‘HTML responses or pages without expected tags
  • Pages with no images or where images are relative paths

Wrap in Promises if you prefer async/await usage.


Edge Cases & Limitations

  • Pages behind authentication will fail
  • Dynamically loaded content via JavaScript is not supported
  • Relative image URLs may need to be resolved manually
  • Multiple images on a page โ€” first or OG image is chosen

Development

  1. Clone the repo:
git clone https://github.com/thiagofeijodev/node-link-previewer.git
cd node-link-previewer
  1. Install dependencies:
npm install
  1. Run tests (when available):
npm test

Contributing

  • Fork the repo & create a feature branch
  • Write tests for new behavior
  • Maintain consistent code style
  • Open a pull request with clear description of changes

License

MIT License โ€” see LICENSE for details.

About

๐Ÿ”—๐Ÿ‘๏ธ Library to return title, description and highlighted image of a site to generate a link preview.

Topics

Resources

Stars

Watchers

Forks

Packages

Used by

Contributors

Languages