npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

lighthouse-tracker

v1.0.1

Published

Service to run Lighthouse against a website and parse the results

Downloads

8

Readme

Lighthouse Tracker

Run Lighthouse against your website, parse the JSON result for only those metrics that are useful, and return the result. From there you can track whether your key metrics are improving (or not).

Motivation

You can read about the thinking behind this here: but basically, we wanted a way to run Lighthouse against our site whenever we released a build via CircleCI.

Installation

Either npm:

npm install lighthouse-tracker

Or yarn:

yarn add lighthouse-tracker

Commands

lighthouse.run(url)

This returns a Promise with data in the format below. It's up to you how you want to store/display that data e.g. save to a database, POST to a service like Datadog.

[
  {
    "date": "2019-03-01T07:57:59.368Z",
    "url": "https://anucreative.com/",
    "id": "first-contentful-paint",
    "title": "First Contentful Paint",
    "rawValue": 1118.575,
    "displayValue": "1.1 s",
    "score": 1
  },
  {
    "date": "2019-03-01T07:57:59.368Z",
    "url": "https://anucreative.com/",
    "id": "first-meaningful-paint",
    "title": "First Meaningful Paint",
    "rawValue": 1251.874,
    "displayValue": "1.3 s",
    "score": 1
  },
  {
    "date": "2019-03-01T07:57:59.368Z",
    "url": "https://anucreative.com/",
    "id": "speed-index",
    "title": "Speed Index",
    "rawValue": 1655,
    "displayValue": "1.7 s",
    "score": 1
  }
  ...
]

It currently returns the following metrics:

[
  'first-contentful-paint',
  'first-meaningful-paint',
  'speed-index',
  'network-requests',
  'interactive',
  'total-byte-weight',
  'uses-webp-images',
  'uses-optimized-images',
  'uses-responsive-images'
]

Example (simple)

1. Create a runner file

// lighthouse-runner.js

const lighthouse = require('lighthouse-tracker')

const saveData = data => {
  // Post to your favourite data store
}

// Run
lighthouse
  .run("https://welcometothejungle.com")
  .then(saveData)
  .catch(console.error)

2. Run your file from npm scripts

// package.json

{
  "scripts": {
    "lighthouse": "node ./lighthouse-runner.js",
  }
}

Example (more involved)

1. Create a runner file that will read the URL from the command line arguments

// lighthouse-runner.js

const path = require('path')
const dogapi = require('dogapi')
const lighthouse = require('lighthouse-tracker')
const parseArgs = require('minimist')

require('dotenv')

// Get URL from arguments
const argv = parseArgs(process.argv.slice(2))
const url = argv._[0]
if (!url) {
  throw Error('No URL provided')
}

// Post to Datadog
const postToDataDog = metrics => {
  dogapi.initialize({
    api_key: process.env.DATA_DOG_API_KEY,
    app_key: process.env.DATA_DOG_APP_KEY
  })
  return dogapi.metric.send_all(metrics, (err, res) => {
    if (err) {
      throw new Error(err)
    }
    console.dir(res)
  })
}

// Run
lighthouse
  .run(url)
  .then(postToDataDog)
  .catch(console.error)

2. Set up the npm task (same as first example)

// package.json

{
  "scripts": {
    "lighthouse": "node ./lighthouse-runner.js",
  }
}

3. Call the lighthouse npm task from Circle with a URL

// .circleci/config.yml

jobs: 
  lighthouse:
    steps:
      - run: yarn lighthouse https://$AUTH_USER:[email protected]
      - store_artifacts:
          path: reports/lighthouse 

Todo

  • Tests
  • Accept more Lighthouse arguments (e.g. throttle, list of metrics)
  • Multiple passes taking median results