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

micro-nervous

v2.0.5

Published

a minimal micro-services framework

Downloads

22

Readme

Travis Codecov License

Install

npm install micro-nervous

Note: Node version 6.0.0 or higher is required.

Overview

const { Nerve, Stats, Service } = require('micro-nervous');

// 'Nerves' are simple class wrappers for Resources or Connections
class RedisNerve extends Nerve {
  init() {
    // Connection logic goes here:
    this.redis = new Redis('redis://:[email protected]:6379');

    // When our connection is ready, just fire the `ready` event
    this.redis.once('ready', () => this.fire('ready'));
  }
  exit() {
    // Disconnection logic goes here, as expected:
    redis.once('end', () => this.fire('end'));
    redis.disconnect();
  }
}

// Nerves are re-usable, so can be shared between different microservices
const nerves = [
  new RedisNerve('pub'),
  new RedisNerve('sub'),
];

// A stats instance serves healthchecks and stats over http
const stats = new Stats({ port: 3000 });

// Instance of the Service class just ties together Nerve instances and stats
const service = new Service({ nerves, stats });

// This gives you an event emitter, nothing too special
service.on('ready', () => console.log('Your service is ready!'));

// But this can be useful
service.on('end', code => process.exit(code));

// Events fired by your Nerves are prefixed with their name
service.on('pub-ready', () => console.log('Publish Nerve is ready');

// Service#poweroff shuts down your connections gracefully
process.once('SIGTERM', () => service.poweroff());

// Just like Service#connect gets your connections started
service.connect();

// You also get access to the Nerve instances
service.nerve.sub.redis.subscribe('channel', (message) => {
  // And a tasking system to prevent unwanted shutdowns
  const task = service.newTask();
  // Now Service#poweroff will wait...
  // You can do lots of stuff... async stuff...
  // And even if you get a SIGTERM, from say, kubernetes...
  // Your task be allowed to finish before your connections are dropped!
  console.log('Yay, message:', message);
  task.done();
});

// The Nerve instances are attached using the keys used in the constructor
service.nerve.pub.redis.publish('channel', 'hello world!');

Healthchecks

Once you call Service#start you can hit http://host:3000/ok (or the port of your choosing) for that 200 OK feeling! Obviously that goes away the moment something goes wrong. Or when you call Service#poweroff, I guess.

Stats

You can also hit http://host:3000/stats for some sweet, sweet json. For example:

{
  "ok": true,
  "currentTasks": 0
}

The stats json just comes from service.getStats(), which can be easily overwritten

class MyService extends Service {
  getStats() {
    return {
      ok: this.ok,
      currentTasks: this.stats.currentTasks,
      answer: askDeepThought(),
    };
  }
}

Incidentally, stats.ok is used for the healthcheck: true for 200, anything else gives you a 503.

Roadmap

Some features that might make it into future versions, in no particular order:

  • Example Nerves for common resources, e.g. Redis, Mongo, etc.
  • Type annotations for Closure Compiler

Contributing

All help is appreciated! Feel free to fork, branch master and open a PR. Thanks!