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

chef-uws

v2.1.3

Published

chef-js + uWebSockets.js = static files server + websockets

Downloads

63

Readme

chef-uws

web-sockets micro-service manager and static files server at the same port,

designed for node written in typescript, with tests

  • uWebSockets.js for serving files and websockets

Command-Line Running

$ npx chef-uws folder [--debug] [--ssl] [--port 443] [--plugin path/to/plugin.js]

Installation

$ yarn add chef-uws

Minimal Chat Demo

https://chef-js-uws.herokuapp.com/

$ yarn add chef-uws
$ yarn chef-uws node_modules/chef-uws/demo --plugin node_modules/chef-core/chat.js

Minimal configuration is specifying folder, then it serves it from http://localhost:4200

const startServer = require("chef-uws");
const config = { folder: "docs" };

startServer(config).then((server: uWS.App | uWS.SSLApp) => {
  // server api is get, post, any
  server.any("/*", (res: uWS.HttpResponse, req: uWS.HttpRequest) => {
    res.end("200 OK");
  });
});

Configuration

For more information about config parameters read:

  • The default configuration https://github.com/chef-js/core#configuration

  • The parameters types https://chef-js.github.io/core/types/Config.html

Plugins

The plugins are a mighty thing, think of them like chat rooms,

after a client handshakes the chat room, his messages start being forwarded to that room,

and it is being handled there by the room's own plugin.

This means you can have for example: a chat server and other unrelated websocket services

at the same port as the files server too. One client may be in many rooms.

STEP 1: Before Connection

  • client -> websocket connects to location.origin.replace(/^http/, 'ws')
  • server -> waits for any incoming config.join events

STEP 2: Connection

  • client -> sends join event with room name (topic/plugin name)
  • server -> if such plugin is configured joins client to that plugin

STEP 3: After Connection

  • client -> does some actions (emits, receives)
  • server -> plugin responds to websocket actions

STEP 4: Finish Connection

  • client -> disconnects after some time
  • server -> broadcasts to all plugins from room that client left (config.leave)

API

  • a plugin is a function (ws, { id, event, data }) that is called each time the frontend websocket emits to server
  • context (this) of each plugin is the server instance.
  • plugins receive (and send) the data in the format of:
{
  id,    // WebSocket id - this is automatically added
  event, // event name as string
  data,  // any data accompanying the event
}

Client

front-end websocket client for uWebSockets.js with same API as socket.io-client:

<script src="https://unpkg.com/chef-uws@latest/client.js"></script>

you can use it like this:

const UWebSocket = require("chef-uws/client");
// will connect to ws:// or wss:// protocol depending on ssl enabled or not
const ws = new UWebSocket(location.origin.replace(/^http/, "ws"));

ws.on("connect", () => {
  // after connect, join a plugin (chat) - emit "/join" event with data = "chat"
  ws.emit("/join", "chat");
});
ws.on("disconnect", () => {
  // your socket got disconnected
});
ws.on("/join", (id, event, data) => {
  // socket with id joined plugin, first join sets your socket's id
  ws.id = ws.id || id;
});
ws.on("/leave", (id, event, data) => {
  // socket with id left plugin
});
ws.on("example", (id, event, data) => {
  // handle event with "example" name
});
ws.onAny((id, event, data) => {
  // handle all incoming messsages
});

License

MIT