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

on-line

v0.1.1

Published

Check if the internet connection is up

Downloads

10

Readme

on-line Build Status

Check if the internet connection is up

Works in Node.js.

In the browser you have navigator.onLine, but it's useless as it only tells you if there's a local connection, and not whether the internet is accessible.

Install

$ npm install --save on-line

Usage

The basic use

var isOnline = require('on-line');

isOnline(function(err, online) {
  console.log(online);
  // => true
});

Custom options

var isOnline = require('on-line');
isOnline({ timeout: 1000, server: '199.7.83.42' }, function(err, online) {
  console.log(online);
  // => true
});

Node API

isOnline([options,]callback)

options

Optional
Type: object

timeout

Type: number

Milliseconds to wait for a server to send response.

server

Type: string

Testing server.

callback(error, online)

Required
Type: function

error is there only by Node.js convention and is always null.

How it works

In node, we first contact one of the thirteen root servers and ask them to direct us to the servers which host the <root> zone (Which they are themselves). If the server answers, we return an online status.

If no satisfying answer is given within one second, we return an offline status. In the rare case where an firewall intercepts the packet and answers it on its behalf, a second check is run which tries to connect to a series of popular web sites on port 80. If one of these connects, we return online, otherwise offline status.

In the browser, a sophisticated check like in node is not possible because DNS and sockets are abstracted away. We use a check which requests an uncached favicon.ico on a series of popular websites. If one of this checks succeeds, we return online status. If all the requests fail, we return offline status.

Thanks

License

MIT