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

respress

v1.1.2

Published

A RESP 'Redis Serialization Protocol' library implementation to generate a server, uses a similar approach to express to define you serer, making it easy and fast.

Downloads

3

Readme

RESPRESS

enter image description here A RESP 'Redis Serialization Protocol' library implementation to generate a server, uses a similar approach to express to define you serer, making it easy and fast. Using this library you can spin off a RESP-TCP server very fast, the server can be connected to using any redis compatible library or tool like redis-cli or ioredis . You can find a server example in the example folder.

Installation

Simply install the library using

npm install respress --save

to use it just require the library

Getting Started

let  RESPRESS = require("respress");
let  app = new  RESPRESS();

Now you are ready to spin off your server, it is very similar to express, the idea was to keep it simple for developers to implement RESP in their code.

let  RESPRESS = require("respress");
let  app = new  RESPRESS();

//Register a command PING which accepts multiple arguments and is returned 
//in req.params.message
app.cmd("PING [message...]", (req, res) => {
    if (req.params.message) {
        res.send(req.params.message);
    }
    else {
        res.send("PONG");
    }
})

//Listen to client connections through the events provided 
app.on("clientConnect", (client) => { console.log("NEW CLIENT YAY!", client.id) });

//Start server and listen to port 9001
app.listen({port:9001} , (server) => {});

Now you can use the server, lets use redis-cli to connect

$ redis-cli -p 9001 -a letMeIn!
127.0.0.1:9001> ping
"PONG"
127.0.0.1:9001> 

Yes, it is that simple. Now lets get into details.

Take a look at the example server, will make your life easier. Link to example

Registering Commands

As seen before to register commands its simple. There are many things you can use to register commands and will be described below.

A simple command with no arguments

The command "COMMAND" is registered, once it is called by the client the handler function is called returning req and res. Req can be used to capture parsed commands and arguments where as res can be used to respond to the client.

app.cmd("COMMAND", (req, res) => {
    res.send(app.cmds.commandList)
})

A Command with arguments

Positional arguments can be placed when registering a command, examples below;

//Register a required argument called subcommand, use <> to register required
// req.params.subcommand returns a single string 
app.cmd("CLIENT <subcommand>", (req, res) => {
    if (req.params.subcommand.toLowerCase() == "getname") {
        res.send(req.client);
    }
    else {
        res.send(new Error("Missing correct subcommand"));
    }
})

//Register multiple series of messages as optional, use [] to define its optional and
// use .... after the argument name to indicate that it can be multiple messages, this 
// is returned to req.params.message as an array
app.cmd("PING [message...]", (req, res) => {
    if (req.params.message) {
        res.send(req.params.message);
    }
    else {
        res.send("PONG")
    }

})

//Using the * will be the default handler of commands that are not defined. req.params._ 
//will return an array of all the params tokenized in an array for your usage.
app.cmd("*",(req,res)=>{
    res.send("A Default execution for the command")
})

Authentication

To register an authentication handler all you need to do is use the following code below. the usage of app.auth method to register an authentication handler. req.params.username and req.params.password will be returned for authentication. res.auth() needs to be called with true or false to indicate if authentication was successful.

app.auth((req, res) => {
    if (req.params.password == "letMeIn!") {
        res.auth(true);
    }
    else {
        //You shall not pass
        res.auth(false);
    }
})

Sending Responses

To send responses all command handlers have a res.send() argument that can be used to respond to the clients command request. You can send different response types as below;

res.send("You can send a simple string");
res.send(["Or","send","an", "array"]);
res.send({obj:"An object can be sent and will be stringified"})
res.send(new Error("Error: can be sent and managed correctly by client");
res.sent(()=>{console.log("Sending a function, it will be sent as a string definition."})

Command Argument Definitions

You can use multiple methods to register your positional arguments, below are some examples;

//<argument> is required and [argument] is optional 
get <source> [proxy]'

//Use an alias where <username|email> will populate 
//req.params with both .username and .email with the same value
get <username|email> [password]

//Variadic arguments all to have multiple messages associated to a name. 
// Use ... to indicated variadic arguments. 
// req.params.files will be an array with all messages assigned.
download <url> [files..]

API

The apis can be found in the DOCs folder. Links as follows;

Contribution

Contributions are welcome, if you are interested please let me know and would be happy to get you on-board. Needs help with

  • Unit Tests
  • Code Refactor / Cleanup
  • Add middleware for pre-request and pre-response