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

redux-socket.io-middleware

v1.0.4

Published

Another middleware which allows you to connect your Redux app and Socket.io

Readme

redux-socket.io-middleware

Another dead-simple middleware which allows you to connect Redux and Socket.io. It uses meta property of your action object to recognize whether send it to backend, or not.

Idea

  • Whenever you want to send an event from Client to your Backend through socket.io, use store.dispatch with regular action with meta object (see example actionCreator.js)
  • Whenever you want to send and handle an event from your Backend to Client - emit it on backend with socket.io in a form of regular action and it will be handled by forwarding it to store.dispatch() - your reducers should take care of the rest.

Important side note - action object send thorough Socket.io must be standard javascript object literal. It can't be a function (so unfortunately thunk drops out).

Usage

Installation

npm install --save redux-socket.io-middleware

Client side

store.js

import socketIO from 'socket.io-client';
import socketIoMiddleware from 'redux-socket.io-middleware'

const reducers = (...);

const io = socketIO.connect(`http://localhost:3030`);

const store = createStore(
  reducers,
  applyMiddleware(    
    socketIoMiddleware(io)
  )
);

actionCreator.js

function addUserRequest(user){
  return {
    type: "ADD_USER_REQUEST",
    meta: {remote: true},
    user
  }
}

function addUserRequestSuccess() {
	return {
    	type: "ADD_USER_REQUEST_SUCCESS",       
  }
}

function addUserRequestFailure() {
	return {
    	type: "ADD_USER_REQUEST_FAILURE",       
  	}
}

And then you dispatch this type of action like any other:

yourReactComponentContainer.js

const mapDispatchToProps = function (dispatch) {
  return {
    addUserRequest: (user) => dispatch(actionCreator.addUserRequest(user)),
    }
}

Server side

If we share actionCreator.js between client and server we can youse it like below. Otherwise, just create action by hand.

userController.js

io.on('connection', function (socket) {
    socket.on("action", function (action) {
      switch (action.type) {
        case "ADD_USER_REQUEST":
          return userService.save(action.user).then(
            (user) => io.emit('action', actionCreator.addUserRequestSuccess()),
            (err) => io.emit('action', actionCreator.addUserRequestFailure())
          );
          }
    })
});

Configuration

You can configure the name of channel which will be used for sending websocket messages. Default value is action. To change it, simply add second parameter when registering middleware:

import socketIoMiddleware from './redux-socket.io-middleware'

const store = createStore(
  reducers,
  applyMiddleware(    
    socketIoMiddleware(io, "myRandomChannel")
  )
);

and then on your backend side, listen on that string:

  io.on('connection', function (socket) {
      socket.on("myRandomChannel", function (action) {
        /// ...
      })
  });

Yeah, I know that this readme is much longer than a code itself :)