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

rib-server

v2.0.8

Published

A framework for a Realtime Integrated Backend

Downloads

20

Readme

Rib-Server GitHub license npm version

Rib-Server is the simplest way to create and horizontally scale a realtime backend. This should be coupled with rib-client to create a simple real-time application. Rib-Server allows you to call client-side functions directly from the server.

For the official github, please click here.

Example

let RibServer = require("rib-server").default
RibServer.startServer(5000, "This is much easier to program")

let myRib = new RibServer()
myRib.onConnect((client) => {
    //  call the client-side function sendMSG on all clients except the one that just connected
    myRib.clientFunctions.sendMSG("Someone else joined the party 🎊", { query: { _ribId: { $ne: client._ribId } }})

    // call the client-side function sendMSG for just the newly connected client
    myRib.clientFunctions.sendMSG("Welcome to this example 😃", { query: client })
})

function logMessage(msg) {
    console.log(msg)
}
logMessage.argTypes = ["string"]    //  validates client passed 1st parameter of type string

function add(x, y) {
    return x + y
}
add.argTypes = ["number", "number"]    //  validates client passed 1st & 2nd parameter of type number

myRib.exposeFunctions([logMessage, add])    // allows us to call add & logMessage functions from the client

Documentation

startServer: Static Function

const PORT = 5000
RibServer.startServer(PORT, `Started up on port ${PORT}`)

Starts up a server with a specified port and an optional message log.

setRedisUrl: Static Function

RibServer.setRedisUrl("//localhost:6379")

Link to a redis server. This is for horizontal scaling your application. More can be found on the official redis documentation at https://redis.io/.

setRoute: Static Function

RibServer.setRoute("/", `${ __dirname }/Home/Client/index.html`)

Set a route for your application and the file to send with the associated route.

setClientFolder: Static Function

RibServer.setClientFolder(
    { path: "/Home/Client/", fullPath: `${ __dirname }/Home/Client/` }
)

Set static folder that can be accessed by a client.

setClientFolders: Static Function

RibServer.setClientFolders([
    { path: "/Home/Scripts/", fullPath: `${ __dirname }/Home/Scripts/` },
    { path: "/Home/Styles/", fullPath: `${ __dirname }/Home/Styles/` },
])

Set static folders that can be accessed by a client.

getApp: Static Function

const app = RibServer.getApp()

Get express app to use for middleware.

Instantiate Rib Server:

let myRib = new RibServer()

Note: The constructor takes two optional parameters. The first is the namespace that the client is trying to connect to(default is "/"). The second is whether or not you want to use the singleton design pattern(default is true).

onConnect: Function

myRib.onConnect((client) => {
    console.log(client)
})

Call a function after a client connects to the server. The object given is called a Persistent Client Object(PCO for short). This object is given each time a client calls a serverside function, and you can attach any data to this object and it will be persistent each time that client calls a server side function.

onDisconnect: Function

myRib.onDisconnect((client) => {
    console.log("A client disconnected 🙁")
})

Call a function when a client disconnects from the server. The callback value is a Persistent Client Object(PCO for short).

exposeFunction: Function

function add(x, y) {
    return x + y
}
add.argTypes = ["number", "number"]
myRib.exposeFunction(add)

Expose a server-side function that can be called from the rib-client instance. If argTypes is an added onto the function, aka functionName.argTypes = [], then this function's arguments will be validated before executing the function. Recognized argtypes are "undefined", "object", "boolean", "number", "string", "symbol", "null", and "any".

exposeFunctions: Function

myRib.exposeFunctions([
    add,
    subtract,
    multiply,
])

Expose an array of server-side functions that can be called with a rib-client instance. If argTypes is added onto a function, functionName.argTypes = [], then that function's arguments will be validated before executing the function. Recognized argtypes are "undefined", "object", "boolean", "number", "string", "symbol", "null", and "any".

concealFunction: Function

myRib.concealFunction(add)

Conceal a server-side function where it can no longer be accessed from all clients.

concealFunctions: Function

myRib.concealFunctions([
    add,
    subtract,
    multiply,
])

Conceal server-side functions where they can no longer be accessed from the client.

possibleClientFunctions: Function

myRib.possibleClientFunctions = ["logMessage"]

Gives ability to call your client-side functions with ease of mind by setting an array of possible client-side functions.

call: Function

app.call(
    "logMessage",
    "Log this message client side 👋🏻",
    { query: { locationId: client.locationId } },
)

The safest way to call a client function.

runPOF: Function

const res = await app.runPOF(
    "getName",
    [],
    { locationId: locationId.toString() },
)   //  run function getName on each PCO whose locationId matches specified

Run a persistent object function that matches a query