contextera

Thursday, January 12, 2017

OpenGraph Node Module


Today I tried this Node module OpenGraph and it worked seamlessly.

We just need to do the following steps

Install Open Graph Module

npm install open-graph

Once installed, you can invoke it through your JS code as follows

var openGraph = require('open-graph');
openGraph("http://github.com/samholmes/node-open-graph/raw/master/test.html", function(err, metaTags){
    console.log(metaTags);
});
Output JSON
This will print the meta data tags present in the 
input URL.
The result for this example is
 
{
  title: 'OG Testing',
  type: 'website',
  url: 'http://github.com/samholmes/node-open-graph/raw/master/test.html',
  site_name: 'irrelavent',
  description: 'This is a test bed for Open Graph protocol.',
  image: 
  { 
     url: 'http://google.com/images/logo.gif',
     width: '100',
     height: '100'
  }
}
 
 
One thing that I feel would be very useful is 
to handle sites 
which doesn't have Open Graph meta data tags. 
The author of this module already had this 
in his TODO list. Sounds easy right, then why 
not give it a shot.