DEV Community

Rocktim Saikia
Rocktim Saikia

Posted on

3 2

meta-fetcher: URL meta-data fetcher for Node.js

Hi, Myself Rocktim Saikia. And today I want to showcase a simple project that I have been working on for couple of days now.

meta-fetcher πŸ”Ž

meta-fecther is simple and tiny url meta-data fetcher for Nodejs. Under the hood this module uses node-fetch to fetch the meta tags of given website url and returns the parsed meta-data as a JSON object.

GitHub logo rocktimsaikia / meta-fetcher

Simple metadata scrapper for node.js

meta-fetcher

CI npm

Simple metadata scrapper.

Installation

yarn add meta-fetcher
Enter fullscreen mode Exit fullscreen mode

Usage

import metaFetcher from 'meta-fetcher';

const result = await metaFetcher('https://hoppscotch.io/');

console.log(result);
Enter fullscreen mode Exit fullscreen mode

Output:

{
  "title": "Hoppscotch - Open source API development ecosystem",
  "description": "Helps you create requests faster, saving precious time on development.",
  "image": "https://hoppscotch.io/og.png",
  "url": "https://hoppscotch.io/",
  "siteName": "Hoppscotch",
  "type": "website"
}
Enter fullscreen mode Exit fullscreen mode

API

metaFetcher(input)

Takes one url string as a parameter and returns an object containing the meta-information.

input

type: string
default: 'none'

The url string to be scrapped.

Related

page-scrapper: Node.js scrapper that pulls out all links and images of a given site.

License

2024 MIT Β© Rocktim Saikia




Install

npm install meta-fetcher
Enter fullscreen mode Exit fullscreen mode

Basic Usage

const {fetchMetaData} = require('meta-fetcher');

(async () => {
    const result = await fetchMetaData('https://hoppscotch.io/');
        console.log(result);

    /*
        {
        basic_metadata: {
            website: 'https://hoppscotch.io/',
            title: 'Hoppscotch β€’ A free, fast and beautiful API request builder',
            description: 'A free, fast and beautiful API request builder'
        },
        opengraph: {
            'og:image': 'https://hoppscotch.io/banner.jpg',
            'og:type': 'website',
            'og:title': 'Hoppscotch',
            'og:site_name': 'Hoppscotch',
            'og:description': 'A free, fast and beautiful API request builder',
            'og:url': 'https://hoppscotch.io/'
        },
        opengraph_social: {
            'twitter:card': 'summary_large_image',
            'twitter:site': '@liyasthomas',
            'twitter:creator': '@liyasthomas'
        },
        favicons: [
            'https://hoppscotch.io/icon.png',
            'https://hoppscotch.io/icon.png',
            'https://hoppscotch.io/_nuxt/icons/icon_64x64.9834b3.png'
        ]
        }
    */ 
})();

Enter fullscreen mode Exit fullscreen mode

It can also fetch meta-data from shortened-url.
For example:

const {fetchMetaData} = require('meta-fetcher');

(async () => {
    const result = await fetchMetaData('https://bit.ly/2Fj9sNF');
    console.log(result);
})();
Enter fullscreen mode Exit fullscreen mode

There a few advanced options that you can use before fetching. You can check them in the readme.md section.

If you like the project. Do leave a star at repo 🌟

Top comments (4)

Collapse
 
ramanjaneyakarnati profile image
Ramanjaneya K β€’

Best metadata fetching tools i came across: bit.ly/3sQHiwg

Collapse
 
shoaibsharif profile image
Shoaib β€’

I really like the idea of your website. I have noticed that you used netlify function. Would you mind sharing us what did you use to fetch metadata on your website?

Collapse
 
yellow1912 profile image
yellow1912 β€’

Thanks for sharing. Starred. I may need it later.

Collapse
 
rocktimsaikia profile image
Rocktim Saikia β€’

Sure 😊 . Glad you liked it

11 Tips That Make You a Better Typescript Programmer

typescript

1 Think in {Set}

Type is an everyday concept to programmers, but it’s surprisingly difficult to define it succinctly. I find it helpful to use Set as a conceptual model instead.

#2 Understand declared type and narrowed type

One extremely powerful typescript feature is automatic type narrowing based on control flow. This means a variable has two types associated with it at any specific point of code location: a declaration type and a narrowed type.

#3 Use discriminated union instead of optional fields

...

Read the whole post now!

πŸ‘‹ Kindness is contagious

Please leave a ❀️ or a friendly comment on this post if you found it helpful!

Okay