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 🙏

© 2025 – Pkg Stats / Ryan Hefner

socketer

v0.1.1

Published

Socket.io utility to test node.js express applications

Readme

socketer

Socket.io utility for testing socket.io/express applications.

Installation

npm install --save-dev socketer

Usage

This lib provides 5 methods:

  1. anonSocket
  2. authSocket
  3. anonRequest
  4. authRequest
  5. getUrl

Comprehensive documentation exists here: http://socketer.ramseydsilva.com/global.html#anonRequest

anonSocket

anonSocket takes your express app as an argument and a callback that returns an anonymous socket that you can use to poll your server as an anonymous user.

var socketer = request('socketer');

socketer.anonSocket(app, function(socket) {

  socket.once('connect', function() {
    console.log('I am connected!');
  });
  
  socket.once('my-event', function() {
  
    console.log('My event is happening');
    socket.disconnect(); // Call this to disconnect after your function to uninterupt further connect events
  });
  
};

authSocket

authSocket takes your express app as an argument, login credentials in the form of a dict, login url, and a callback that returns a socket that has been authenticated via the login url.

var socketer = request('socketer');

socketer.authSocket(app, {'username': 'Ramsey', 'password': 'Ramseypass'}, '/login', function(socket) {

  socket.once('connect', function() {
    console.log('I am connected as Ramsey!');
  });
  
});

The login url accepts a post method, and csrf has to be turned off for testing. In your app.js file, you can have something like:

if (process.env.NODE_ENV == 'production') {
    app.use(express.csrf());
    app.use(function(req, res, next) {
        res.locals.token = req.csrfToken();
    });
};

// or

if (process.env.NODE_ENV != 'mochaTesting') {
    app.use(express.csrf());
    app.use(function(req, res, next) {
        res.locals.token = req.csrfToken();
    });
};

anonRequest

This method attempts a logout before fetching your request, just in case your request module has previously been configured to save cookies (like we do in ours). You can optionally specify a logout url. The default is '/logout'.

socketer.anonRequest(app, album.editUrl, '/alt-logout', function(err, res) {
    res.statusCode.should.be.exactly(403);
});

authRequest

This method logs a user in. It takes a dict containing the post params to the login page. The default login url is '/login', but you can optionally specify your own.

socketer.authRequest(app, album.editUrl, {email: user.email, password: user.profile.passwordString}, function(err, res) { 
    res.statusCode.should.be.exactly(200);
});

getUrl

This helper method takes in your express app and a root relative path and constructs an absolute url. It also takes an optional protocol such as 'http' or 'ws' etc. The default is 'http'.

console.log(socketer.getUrl(app, post.editUrl, 'ws');
// prints ws://127.0.0.1:4000/posts/1234/edit

Tips

  1. After every test and before you call the done method, you can choose to disconnect the socket by calling socket.disconnect();. This ensures uninterupted successive socket reconnects.
  2. Instead of using socket.on(event), consider using socket.once(event) in your tests. This ensures the event listener stops listening if the event occurs in successive tests.

Dependencies

This library simulates the client socket using socket.io-client package. Different versions of this package might differ in its implementation. During the time time of writing this lib, the versions I was using was:

  1. express: ~3.5.1
  2. socket.io: ~0.9.16
  3. socket.io-client: ^0.9.16

Issues

If you notice any issues with the lib, or any compatibilty issues with the versions you are using, let us know. If you want to extend this library with more helper functions also do let us know here: https://github.com/ramseydsilva/socketer/issues

Credits

This library was inspired by the following gist: https://gist.github.com/jfromaniello/4087861