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

psi-ngrok

v0.1.2

Published

PageSpeed Insights with local project

Downloads

11

Readme

psi-ngrok Build Status

PageSpeed Insights with local project

Uses psi and ngrok for running PageSpeed Insights for locally run web application.

Inspired by

Install

$ npm install --save-dev psi-ngrok

Usage

const psiNgrok = require('psi-ngrok');

psiNgrok();

Usage with configuration

const psiNgrok = require('psi-ngrok');

const config = {
  pages: ['page1.html', 'page2.html'],
  onBeforeConnect: function() {
    // do somtheng before ngrok is connected to your host
  },
  //called if page passed `threshold` limit
  onSuccess: function(data) {
    console.log(data); // all PSI data about page
  },
  //called if page didn't pass `threshold` limit
  onError: function(error) {
    console.log(error); // error message
  },
  options: {
    threshold: 85
  }
};

psiNgrok(config);

Also look at recipes.

Usage with Grunt

Here example of using psi-ngrok with grunt-connect


var psiNgrok = require('psi-ngrok');

module.exports = function(grunt) {

  grunt.initConfig({
    connect: {
      server: {
        options: {
          port: 8000,
          base: 'public'
        }
      }
    },
  });

  grunt.loadNpmTasks('grunt-contrib-connect');

  grunt.registerTask('pagespeed', function() {
    var async = this.async;

    grunt.event.once('connect.server.listening', function(host, port) {
      psiNgrok({
        port: port,
        pages: ['index.html', 'slow.html'],
        onError: function(error) {
          grunt.fatal(error);
        },
        options: {
          threshold: 80
        }
      }).then(async());
    });
  });

  grunt.registerTask('default', ['pagespeed', 'connect:server:keepalive']);
};

Want to test it?

Run

  • git clone https://github.com/denar90/psi-ngrok && cd psi-ngrok && npm i
  • npm run grunt-example

Usage with Gulp

Here example of using psi-ngrok with gulp-connect


var gulp = require('gulp');
var connect = require('gulp-connect');
var psiNgrok = require('psi-ngrok');
var port = 8000;

var connectServer = function() {
  return connect.server({
    root: 'public',
    port: port
  });
};

function handleError(err) {
  console.log(err.toString());
  process.exit(-1);
}

gulp.task('pagespeed', function () {
  psiNgrok({
    pages: ['index.html', 'slow.html'],
    port: port,
    onBeforeConnect: connectServer,
    onError: handleError,
    options: {
      threshold: 80
    }
  });
});

gulp.task('default', ['pagespeed']);

Want to test it?

Run

  • git clone https://github.com/denar90/psi-ngrok && cd psi-ngrok && npm i
  • npm run gulp-example

API

psiNgrok([config])

Returns a promise for the response data from Google PageSpeed Insights for pages run locally.

config

Type: object

strategies

Type: array Default: ['mobile', 'desktop'] Values: mobile, desktop

Strategies to use when analyzing the page.

pages

Type: array Default: ['/']

List of local pages which will be analyzed.

port

Type: number Default: 8000

Port local server running at.

onBeforeConnect

Type: function Default: Function.prototype

Function called before ngrok is started.

Useful for running local server.

onSuccess

Type: function Default: Function.prototype

Function called each time page(s) passed threshold limit. Has data argument which consist of all PSI data about page.

onError

Type: function Default: Function.prototype

Function called each time page(s) didn't pass threshold limit. Has error argument - message about what went wrong.

options

Type: object

Pretty the same as psi options

key

Type: string Default: Free tier

When using this module for a production-level build process, registering for an API key from the Google Developer Console is recommended.

locale

Type: string Default: en_US

Locale results should be generated in.

threshold

Type: number Default: 70

Threshold score to pass the PageSpeed test. Useful for setting a performance budget.

MIT © Artem Denysov