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

sockpress

v1.4.1

Published

A simple express.js and socket.io wrapper

Downloads

61

Readme

sockpress Build Status

A simple express.js and socket.io wrapper for nodejs

Why ?

Because building an app with express and socket.io could be complex and redundant, here is a really small wrapper to work with latest versions of express.js and socket.io

Install

yarn install sockpress

Important note: sockpress leverages JavaScript modules since its 1.4.0 version. It is bundled with the excellent esm module for retro-compatibility.

How to use ?

Sockpress adds the socket.io object to the express one. It does not change express or socket.io properties, but adds some useful features.

Init Sockpress

Sockpress initialization creates express and socket server with automatic shared session support.

import sockpress from "sockpress"
const app = sockpress([express], [options])

An example to work with classic session store (memory) :

const options = {
  secret: "a secret key",
  saveUninitialized: false
}
const app = sockpress(options)

An example to work with connect-redis session :

const session = require('express-session')
const RedisStore = require('connect-redis')(session)

const options = {
  secret: "a secret key",
  store: new RedisStore({host:'127.0.0.1'}),
  name: "my-cookie-key"
}
const app = sockpress(options)

List of available options for sessions

If you dont want sockpress to create a session store, just pass options.disableSession = true parameter.

Use it with HTTPS

You can use sockpress as a HTTPS server. Just pass a https option to sockpress, containing https details.

const options = {
  secret: "a secret key",
  https: {
    key: privateKey,
    cert: serverCert,
  },
}
const app = sockpress(options)

List of available options for https

Add express middlewares as usual

You can include your favorite express middleware like a classic express app ! For convenience, sockpress exposes the express raw object in app.express.

app.use(app.express.static(require("path").join(__dirname, "static")))

Important : use Express 4 middlewares, see documentation.

Define routes

For classic routes, you don't have to change your code. See express docs.

app.get("/index", (req, res) => {
  res.send("Hello World!")
})

For IO routes and configuration, you can use the app.io object, and use it as a classic socket.io object. See socket.io docs.

app.io.on("connection", (socket) => {
  socket.emit("welcome", "Hi ! Welcome on Sockpress server.") //send to the connected socket
  socket.broadcast.emit("newUser") //broadcast to other users
})

You can also use a fresh utility provided by Sockpress : app.io.route(socket, data)

app.io.route("send message", (socket, data) => {
  socket.emit("message sent", data)
  socket.broadcast.emit("new message", data)
})

It also supports socket.io namespaces :

app.io.route("/users", "send message", (socket, data) => {
  // ...
})

Use session inside IO routes

app.io.route("action", (socket, data) => {
  if(socket.session.authenticated) {
    socket.session.foo = "bar"
    socket.session.save()
  }
})

Warning : you have to call the socket.session.save([callback]) function after updating the session inside a IO route.

Start Sockpress !

app.listen(3000)
// or
app.listen(3000, "127.0.0.1")

see nodejs http(s) doc

Test Sockpress

git clone https://github.com/Lesterpig/sockpress.git
cd sockpress
npm test

(Advanced) Use modular routes system

If your application uses a modular approach, you would be interested by the modular routes syntax. Here is an example where we define a route and then plug it into the sockpress server.

const myRoute = app.io.Route()

// Define route
myRoute
.on('connection', (socket) => {
  // On new connection (standard approach)
})
.use((socket, next) => {
  // On new connection too (middleware approach)
})
.event('name', (socket, data) => {
  // On particular event
})

// Plug route!
app.io.route('/namespace', myRoute)

Project Status

This project is maintained for bug fixes and compatibility with newer versions of express/socket.io, but no new features are planned. It should then be considered "Stable".

Authors: