OGP PARSER

A npm package that extracts Open Graph Protocol (ogp.me) metadata from a given URL that can be used to generate link previews.
Installation
To install @notamit/ogpparser
npm install @notamit/ogpparser --save
yarn add @notamit/ogpparser
pnpm add @notamit/ogpparser
bun add @notamit/ogpparser
🧰 Usage
@notamit/ogpparser
exports parse
async function. It requires 1 argument, the URL of the page you want to extract metadata from. It returns a promise that resolves to an object containing the metadata.
Inside your .js/.ts
file, import the parse
function and use it.
import parse from "@notamit/ogpparser";
async function test() {
const metadata=await parse('https://www.youtube.com/watch?v=znWS3zkdrq4');
return metadata;
);
test().then(res =>{
console.log(res);
}).catch(err =>{
console.error(err);
})
}
Sample response:
{
title: 'Chai aur code Live ☕️ - YouTube',
og: {
'og:site_name': 'YouTube',
'og:url': 'https:
'og:title': 'Chai aur code Live ☕️',
'og:image': 'https:
'og:image:width': '1280',
'og:image:height': '720',
'og:description': 'https:
'og:type': 'video.other',
'og:video:url': 'https:
'og:video:secure_url': 'https:
'og:video:type': 'text/html',
'og:video:width': '1280',
'og:video:height': '720'
},
twitter: {
'twitter:card': 'player',
'twitter:site': '@youtube',
'twitter:url': 'https:
'twitter:title': 'Chai aur code Live ☕️',
'twitter:description': 'https:
'twitter:image': 'https:
'twitter:app:name:iphone': 'YouTube',
'twitter:app:id:iphone': '544007664',
'twitter:app:name:ipad': 'YouTube',
'twitter:app:id:ipad': '544007664',
'twitter:app:url:iphone': 'vnd.youtube:
'twitter:app:url:ipad': 'vnd.youtube:
'twitter:app:name:googleplay': 'YouTube',
'twitter:app:id:googleplay': 'com.google.android.youtube',
'twitter:app:url:googleplay': 'https:
'twitter:player': 'https:
'twitter:player:width': '1280',
'twitter:player:height': '720'
},
alternateImage: 'https:
description: 'https:
keywords: 'video, sharing, camera phone, video phone, free, upload'
}
PACKAGE
@notamit/ogpparser
PARAMS
Parameters
⚙️ Configuration
Setting | Value |
---|
Runtime | Nodejs>=(18.12.1) |
Entrypoint | src/index.ts |
Build Commands | npm run start |
Author
Amit Jimiwal