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 🙏

© 2026 – Pkg Stats / Ryan Hefner

backendium

v0.0.21

Published

Express-based javascript backend framework with websocket support

Downloads

656

Readme

Table of Contents

  1. Installation
  2. Basics
  3. Routing
  4. Request validation
  5. Authorization
  6. Dynamic routing
  7. Websocket

Installation

npm i backendium checkeasy

Basics

import Backendium from "backendium";

const app = new Backendium;

app.get("*", (request, response, app, next) => {
    response.end({backendium: "0.0.0"});
});

app.start();

request:

curl http://localhost:8080/

response:

{"backendium":"0.0.0"}

Routing

Router class

// main.ts
import Backendium from "backendium";
import handlers from "./handlers.js";

const app = new Backendium;

app.router(handlers);

app.start();
// handlers.ts
import {BackendiumRouter} from "backendium";

const router = new BackendiumRouter;

router.get("*", (request, response, app, next) => {
    response.end({backendium: "0.0.0"});
});

export default router;

Backendium class extends BackendiumRouter

Methods

router.get("/route", (request, response, app, next) => {
    // handler
});

router.post("/route", (request, response, app, next) => {
    // handler
});

Supported methods:

"get", "post", "put", "delete", "patch", "options", "head", "checkout", "connect", "copy", "lock", "merge", "mkactivity", "mkcol", "move", "m-search", "notify", "propfind", "proppatch", "purge", "report", "search", "subscribe", "unsubscribe", "trace", "unlock", "link", "unlink"

Request validation (checkeasy)

Checkeasy imports:

import {int, object, string, strToInt} from "checkeasy";
router.post<{n: number}>("/validated", (request, response) => {
    console.log(request.body);
    response.end(Math.sqrt(request.body.n));
}, {
    bodyValidator: object({
        n: int()
    })
});
curl http://localhost:8080/validated -d '{"n": 2}'

Query

router.get<Buffer /*default type for request body*/, {}, {n: number}>("/validated/query", (request, response) => {
    console.log(request.query);
    response.end(Math.sqrt(request.query.n));
}, {
    queryValidator: object({
        n: strToInt()
    })
});
curl "http://localhost:8080/validated/query?n=2"

Headers

router.get<Buffer, {}, {}, undefined, {n: number}>("/validated/headers", (request, response) => {
    console.log(request.headers);
    response.end(Math.sqrt(request.headers.n));
}, {
    headersValidator: object({
        n: strToInt()
    }, {ignoreUnknown: true})
});
curl http://localhost:8080/validated/headers -H "n:2" 

Authorization

const USERS: {[key: number]: string} = {
    54: "sizoff"
}

router.post<Buffer, {}, {}, string>("/auth", (request, response) => {
    console.log(request.auth); // type of request.auth is string
    response.end();
}, {
    authChecker(request, response) {
        if (typeof request.headers.auth !== "string" || !(Number(request.headers.auth) in USERS)) return null; // auth failed
        return USERS[Number(request.headers.auth)]; // return auth data
    }
});
curl http://localhost:8080/auth -H "auth:54" -d ""

Global (for router)

const router = new BackendiumRouter<string>;

const USERS: {[key: number]: string} = {
    54: "sizoff"
}

router.setAuth((request, response) => {
    if (typeof request.headers.auth !== "string" || !(Number(request.headers.auth) in USERS)) return null; // auth failed
    return USERS[Number(request.headers.auth)]; // return auth data
});

router.post("/auth", (request, response) => {
    console.log(request.globalAuth); // type of request.globalAuth is string
    response.end();
}, {
    auth: true
});

Dynamic routing

More info: https://expressjs.com/en/guide/routing.html#route-paths

router.get<Buffer, {n: number}>("/dynamic/:n", (request, response) => {
    console.log(request.params);
    response.end(Math.sqrt(request.params.n));
}, {
    paramsValidator: object({
        n: strToInt()
    })
});
curl http://localhost:8080/dynamic/2

Websocket

router.ws("/ws")
    .on("message", (data, socket) => {
        console.log(data.toString()); // data is Buffer
        socket.send(data);
    });

js build-in websockets:

const connection = new WebSocket("ws://localhost:8080/ws");
connection.send("test");
connection.onmessage = (message) => {
    console.log(message.data);
};

Backendium connect

import {websocketRequest} from "backendium-connect";

websocketRequest()
    .on("message", (data, socket) => {
        console.log(data); // data is Buffer
    })
    .send("ws://localhost:8080/ws")
    .then(socket => {
        socket.send("test");
    });

Events

router.ws("/ws")
    .event<number>("sqrt", (data, socket) => {
        console.log(data);
        socket.emit("response", Math.sqrt(data));
    }, int());

only Backendium connect

websocketRequest()
    .event<number>("response", data => console.log(data), float())
    .send("ws://localhost:8080/ws")
    .then(socket => {
        socket.emit("sqrt", 2);
    });

Init

router.ws<string>("/ws-init")
    .event("test", (data, socket) => {
        socket.send(socket.initData);
    })
    .requireInit<number>((socket, data) => {
        if (!(data in USERS)) return null; // auth failed
        return USERS[data]; // return auth data
    }, int());
websocketRequest<number>()
    .on("message", data => {
        console.log(data.toString());
    })
    .send("ws://localhost:8080/ws-init", 54)
    .then(socket => {
        socket.emit("test");
    });