1.1.0 • Published 9 years ago

opengraphjs v1.1.0

Weekly downloads
3
License
MIT
Repository
github
Last release
9 years ago

OpenGraphJS

OpenGraphJS builds a JSON object from a web page which follows the Open Graph Protocol. The JavaScript object returned by this library contains important metadata such as the description, image, and title.

Code Climate Build Status Test Coverage npm

Installation

npm install opengraphjs

Usage

Promise support

  • Its easy, if you are using a version of node with Promises you are ready to go!
  • Other versions of node:
    • define global.Promise = require('bluebird');
    • Feel free to substitute Bluebird with your perferred promise library
// Include it
var ogjs = require('opengraphjs');
// Pass in a URL
ogjs({ url: 'http://senorcris.com' })
  .then(function (data) {
    console.log(data); // some share data parsed from metatags..
  }, function (err) {
    console.log('It seems that we have fumbled with an error', err);
  });

Callbacks

// Include it
var ogjs = require('opengraphjs');
// Pass in a URL
ogjs({ url: 'http://senorcris.com' }, function (err, data) {
    if (err) {
      console.log('It seems that we have fumbled with an error', err);
      return;
    }
    
    console.log(data); // some share data parsed from metatags..
  });

Expected ouput

Sample

{ 
  title: 'Open Graph protocol',
  type: 'website',
  url: 'http://ogp.me/',
  description: 'The Open Graph protocol enables any web page to become a rich object in a social graph.',
  image: [{ 
    url: 'http://ogp.me/logo.png',
    type: 'image/png',
    width: '300',
    height: '300' 
  }]
}

Supported properties

Credits and Acknowledgements