New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

link-preview-node

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

link-preview-node

Library to return Image URL, Title and Description of a link for generation of preview of the link

latest
Source
npmnpm
Version
1.0.7
Version published
Maintainers
1
Created
Source

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] (dns.js:56:26)
                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.

Keywords

LinkPreview

FAQs

Package last updated on 14 Nov 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts