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

tinyservice

v0.9.1

Published

Tiny and lightweight nodejs framework for creating microservices via tcp protocol

Downloads

10

Readme

tinyservice

A tiny and lightweight microservice framework, created for nodejs. TinyService uses json-messages to exchange between server and client.

Install

npm install tinyservice --save

Server instance

Server instance of microservice, based on TCP-server.

constructor

const Server = require('tinyservice').Server;
const serverInstance = new Server({
    port: 11234
});

Parameters:

  • {Object} options - required parameter to pass options to construct Server instance
  • {number} options.port - required parameter. Port, on which will be listen server

add

Adds handler to listen messages on server Params:

  • {Object<string, number|string|boolean>} pattern - pattern to handle messages on server side. If incoming messages matches pattern - handler will be called with this message.
  • {Function} handlerFunction - function, that will be called if incomingMessage matches pattern. Function must accept two params:
    • {Object} msg - incoming message, that was received
    • {Function} doneFunction - function, that must be called after action was ended. Function receives two params - error and outgoing message. Error - if handler fails, Outgoing message - message to send to client as answer. CALL OF doneFunction is required!

Example:

serverInstance.add({
    property1: 1,
    property2: 2
}, 
    /**
     * Handler function
     * @param {{}} incomingMessage
     * @param {Function} doneFunction
     */
    (incomingMessage, doneFunction) => {
        //...SOME ACTIONS...
        doneFunction(err, outgoingMessage);
    }
)

remove

Removes handler by pattern.

  • {!Object} pattern - required param. Pattern, on which you want to remove handler
  • [{Function} handler] - optional parameter. If not passed - all handlers will be removed
  • [{boolean} strictMode = true] - optional parameter. If passed true - will be removed only actions, that fully matches passed pattern. If passed false - will be removed common patterns.

Example:

server.add({ // will be removed if strict and not strict mode
    a: 1,
    b: 2
}, () => {});

server.add({ // will be removed in non strict mode in this case
    a: 1
}, () => {});

server.remove({
    a: 1,
    b: 2
}/*, true or false */);

close

Closes server instance and unrefs port

Client instance

const Client = require('tinyservice').Client;
const clientInstance = new Client({
    host: '127.0.0.1',
    port: 11234
});

act

Emits message and handles answers from server Params:

  • {!Object} pattern - required parameter. Pattern to send message to server.
  • {Function} callback - callback, that will be called, when server message will received by this call. EXAMPLE
serverInstance.add({
    a: 1,
    b: 2
}, (msg, done) => {
    done(null, {
        message: 'This message will be received by client!'
    })
});

serverInstance.add({
    a: 1
}, (msg, done) => {
    done(null, {
        message: 'This message will be received by client too!!!'
    })    
});

clientInstance.act({a: 1, b: 2}, (err, msg) => {
    //This function will be called two times
    //from both handlers on server
})

close

Closes client instance