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

beacons

v0.0.1

Published

Minimalistic one way communication

Downloads

5

Readme

Beacons

Made by unshiftVersion npmBuild StatusDependenciesCoverage StatusIRC channel

Beacons is small library to send beacons to your server. It's basically a really minimal way of doing one way communication in browsers without any dependency on XHR requests or what ever. Internally it will use Image to do the actual requesting of the resource. So this method will not work when images are blocked. But it's still a great way to send additional debugging information to your server.

When you receive a beacon request on your server make sure you:

  • Respond with a status code 204 and don't return any content.
  • Don't add pointless HTTP headers to the response. Things such as Cookie headers are not needed and only add pointless bandwidth to these micro requests.

Once the beacon specification lands in the browsers we will start supporting it transparently. See http://w3c.github.io/beacon/ for the current working draft.

Installation

This module is only written for browser usage and assumes that a node.js module system is used for requiring the module. The module it self is released in npm and can be installed from the CLI using the following command:

npm install --save beacons

Usage

The API is as tiny as the module it self. It only exposes one function that does the request. This function accepts 3 arguments, the last 2 are optional.

  1. url The URL you want to request.
  2. fn An optional completion callback, it will be called when the resource is loaded, failed to load or times-out. It's not a guarantee that the message is actually send as that is nearly impossible to detect.
  3. timeout The timeout before the callback is called. Defaults to 1000 ms.

So using this module is as simple as:

'use strict';

var beacon = require('beacons');

beacon('http://example.com/poke', function () {
  console.log('poked example.com');
});

Last but not least, the suggested code to handle the response on the server using Node.js

require('http').createServer(function (req, res) {
  res.statusCode = 404;
  if (req.url !== '/poke') return res.end('404');

  //
  // The actual code that handles the beacon, the code above is just routing of
  // the url..
  //
  res.statusCode = 204;                       // This prevents the need to send a body.
  res.setHeader('Cache-Control', 'no-cache'); // Browsers should never cache this.
  res.end(''); 
});

License

MIT