Link Preview
Description
To show preview of a link, we need to know four things: the link itself, image URL, title and description of the link, the module is here to fulfill the need.
Examples
const { linkPreview } = require(`link-preview-node`);
linkPreview(`npmjs.com`)
.then(resp => {
console.log(resp);
/* { image: 'https://static.npmjs.com/338e4905a2684ca96e08c7780fc68412.png',
title: 'npm | build amazing things',
description: '',
link: 'http://npmjs.com' } */
// Note that '' is used when value of any detail of the link is not available
}).catch(catchErr => {
console.log(catchErr);
});
// In case you are comfortable with callbacks
const { linkPreviewCallback } = require(`link-preview-node`);
linkPreviewCallback(`npmjs.com`, (err, resp) => {
console.log(err ? err : resp);
});
// An error is returned in first argument of callback and catch block of promise when any invalid URL is supplied to the functions
linkPreview(`fdsafsgd.com`)
.then(ans => {
console.log(ans);
}).catch(catchErr => {
console.log(catchErr);
/* { Error: getaddrinfo ENOTFOUND fdsafsgd.com fdsafsgd.com:80
at GetAddrInfoReqWrap.onlookup as oncomplete
errno: 'ENOTFOUND',
code: 'ENOTFOUND',
syscall: 'getaddrinfo',
hostname: 'fdsafsgd.com',
host: 'fdsafsgd.com',
port: 80 } */
});
Reference
I would like to thank Rahul Taneja (https://irtaneja.com/) for helping me in this module. He can be contacted at connect@irtaneja.com.
Report An Issue
If you find any issue in the module, you can report it at https://gitlab.com/nmb94/link-preview/issues.