I'm not sure that you can get the event name from the callback, but you can get around it.
var socket = require('socket.io'); function registerEvent(eventName, cb) { socket.on(eventName, function () { var args = [].slice.apply(arguments); args.unshift(eventName); cb.apply(null, args); }); } registerEvent('my_event', function (eventName, data) {
source share