node package manager


Head Parser

Parse the <head> of documents to get the <title>, <meta, and <link> elements.


var parse = require('head-parser')
var request = require('request')
var req = request('')
parse(req, function (err, res) {
  req.destroy() // destroy the request since we only need to read the <head> 
  res.title === 'GitHub · Build software better, together.'
  res.meta[0] === {
    charset: 'utf-8'
  res.links[0] === {
    rel: 'search',
    type: 'application/opensearchdescription+xml',
    href: '/opensearch.xml',
    title: 'GitHub'


parse(stream, done)

Parses the stream. Since it only reads the <head> of the stream, you can destroy it once the callback is executed.

done returns:

  • err - streams's errors are propagated here until done is executed. Also returns any parsing errors while parsing the <head>.
  • obj - An object with the results:
    • title - the <title> of the document, if any
    • meta[] - an array of meta element attributes
    • links[] - an array of link element attributes