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

comet

v1.0.1

Published

A http long polling comet implementation for nodejs and browser

Downloads

12

Readme

NPM version Required Node version NPM total downloads Contributors License

What is http long polling?

Http long polling is used in real-time application where server pushes the data changes to client using simple HTML5 ajax mechanism.

First client makes a request to an HTTP endpoint in the usual way, with the intention of requesting data it has not yet received. If there is no new data available, then the server holds the request open until data becomes available to respond with. After receiving a response (whether new data or timeout), the transaction is complete. The client may create a new request to listen for further data.

comet

The comet is a implementation of http long polling or comet application model which abstracts the internal http requests and provides high-level websocket alike API.

Installation

Using npm:

$ npm install --save comet

Using yarn:

$ yarn add comet

Usage

Here is simple example to push n-th fibonacci numbers to client:

The server:

import http from 'http';
import CometServer from 'comet/server';

const server = http.createServer();
const pollingServer = new CometServer({ server });

pollingServer.on('connection', (conn, data) => {
  let { fibPos } = data;
  console.log(`New connection with fibpos: ${fibPos}`);

  setInterval(() => {
    conn.send({ pos: fibPos, value: fib(fibPos++) });
  }, 1000);
});

server.listen(8888);

const fib = (n) => {
  let num = 0;
  let num2 = 1;
  let fibonacci;

  for (let i = 0; i < n; i++) {
    fibonacci = num + num2;
    num = num2;
    num2 = fibonacci;
  }

  return num;
};

The client:

import CometClient from 'comet/client';

const fibPos = Math.floor(Math.random() * 10);
const longPollingClient = new CometClient('http://localhost:8888/polling', {
  data: { fibPos },
});

longPollingClient.on('message', (m) => {
  console.log(`${m.pos}th: ${m.value}`);
});

longPollingClient.on('open', (conn) => {
  console.log('Connection opened');
  console.log(`Receiving fibonacci numbers from ${fibPos}th position:`);
});

See example for further guide.

Contributing

Your PRs and stars are always welcome.