node package manager

gpagespeed

Build Status js-standard-style

gpagespeed

Node.js module for analyzing a webpage with Google PageSpeed Insights.

You must acquire an API key from Google Developers Console.

Supports promises and callback interface.

Installation

From npm

$ npm i gpagespeed --save

Usage

Pass an object with properties.

url and key are required, all other are optional.

You can see a list of all alternatives on the page for Google PageSpeed standard query parameters.

Promises

const pagespeed = require('gpagespeed')
const options = {
  url: 'http://url-to-check',
  key: 'insert-your-key'
}
 
pagespeed(options)
  .then((data) => {
    console.log(data)
  })
  .catch((error) => {
    console.error(error)
  })

Callback

const pagespeed = require('gpagespeed')
const options = {
  url: 'http://url-to-check',
  key: 'insert-your-key'
}
 
pagespeed(options, (error, data) => {
  if (error) {
    console.error(error)
  } else {
    console.log(data)
  }
})

Alternative api

In addition you can choose to use https instead of googleapis and another version of the PageSpeed api (defaults to v2).

Promises

const pagespeed = require('gpagespeed')
const options = {
  url: 'http://url-to-check',
  key: 'insert-your-key',
  useweb: true,
  apiversion: 'v3beta1'
}
 
pagespeed(options)
  .then((data) => {
    console.log(data)
  })
  .catch((error) => {
    console.error(error)
  })

Callback

const pagespeed = require('gpagespeed')
const options = {
  url: 'http://url-to-check',
  key: 'insert-your-key',
  useweb: true,
  apiversion: 'v3beta1'
}
 
pagespeed(options, (error, data) => {
  if (error) {
    console.error(error)
  } else {
    console.log(data)
  }
})

Returns

return-example.md

Related

License

MIT

alt text