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

scalable-server

v3.0.2

Published

Unlimited Scalable Server

Downloads

3

Readme

Scalable Server

Initiation


var Server = require('scalable-server');

var config = {
    daemon: {
        port: 8800,
        clients: [],
        servers: [],
        noEvents: false
    },
    test: false
};
var s = new Server(config);

// connect listeners
s.on('connection.new',  function(event) { /* .. code .. */ });
s.on('connection.lost', function(event) { /* .. code .. */ });

s.init();

// connect to additional clients and servers
// this can also be done from the config

s.getDaemon().addClient( port );
s.getDaemon().addServer( address ); // example : ws://localhost:9000/

Options

The options are given to the constructor

Daemon Options

This is in the daemon property of the config object.

  • port Sets the server port on the entered number, the default is 8800
  • clients Adds a connection to a client, this parameter can be repeated when required. This only requires a port number
  • servers Adds a connection to a server, this parameter can be repeated when required. This requires an object with the following attributes
    • hostname The hostname to connect to
    • port The port to connect to
  • noEvents If true, this sets the event handling to message events only. This effectively disables the use of evt.* events.

clients is the shorthand version of servers where the hostname is always "localhost"

Events

Global

  • log This event is emitted every time a log line is executed, this can be used to handle logs in your own way, instead of outputting them to the console

  • message This event is emitted every time a message is received, this is only triggered once per message. The handler for this parameter has 2 parameters;

    • message The message object, this includes the message, user, hashcode and event-type.
    • connection The connection which has send this message.
  • evt.<eventcode> This type of event is send whenever the client or a connected server sends out a message with the event type set. Note: this will be triggered instead of the message event. This can be configured.

    Example:

    Client: { "user": "hank", "event":"request", "method":"sayHello", "params": {} }

    Server: self.emit('evt.request', event);

If you put the returnValue of the EventObject to false, the message will not be send to other servers, nor clients. This allows to respond to an event without alerting the flock.

Connection

  • connection.new This event is emitted when a new connection is established. The handler for this event has one parameter, which is the connection object itself.
  • connection.lost This event is emitted when a connection is lost. The handler for this event has one parameter, which is the connection object itself. Note: one can no longer use this object for sending messages. The connection has been terminated.

Server

  • server.new This event is emitted when a new server-connection is established. The handler for this event has one parameter, which is the connection object itself.
  • server.lost This event is emitted when a server-connection is lost. The handler for this event has one parameter, which is the connection object itself. Note: one can no longer use this object for sending messages. The connection has been terminated.

Sub Modules

TBD

Objects

Submodule


Submodule: {
    server: null,     // Deamon
    // ...
    init:function(){} // Function
}

Connection


Connection: {
    pool: [],                  // ConnectionPool[]
    conn: null,                // Websocket
    // ...
    getIndex: function() {},   // int
    remove: function() {},     // void
    send: function(message) {} // void
}

Connection Pool


ConnectionPool: {
    pool:[],                                      // Connection[]
    // ...
    getPool: function() {},                       // Connection[]
    setPool: function(connections) {},            // void
    add: function(connection) {},                 // Connection
    remove: function(index) {},                   // Connection
    has: function(index) {}                       // boolean
    index: function(connection) {},               // int
    send: function(message, except_connection) {} // void
]

EventObject


EventObject: {
    event: "",         // String
    returnValue: true, // boolean
    // ...
    message: "",       // String
    connection: null   // Connection
}