
Product
Introducing Tier 1 Reachability: Precision CVE Triage for Enterprise Teams
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.
express-io-pubsub
Advanced tools
Express server connects to either a MongoDB capped collection or publishes to a Redis channel. This is accomplished through simple middleware making request.publish(room, event, data) available
Socket.io server connects to the same collection or subscribes to a Redis channel. This is done through a listen command, and then the client can join the room/channel to listen to.
express = require 'express'
http = require 'http'
io = require 'socket.io'
pubsub = require '../../lib/express-io-pubsub'
app = express()
server = http.createServer app
io = io.listen server
app.get '/', (req, res) ->
res.send '
<script src="/socket.io/socket.io.js"></script>
<script>
var socket = io.connect("http://localhost:3001");
socket.on("connect", function(data) {
socket.emit("join room", "lobby");
socket.on("update", function (data) {
var p = document.createElement("p");
var t = document.createTextNode(data.msg);
p.appendChild(t);
document.body.appendChild(p);
});
});
</script>
<body><p>waiting for messages</p></body>
'
io.sockets.on 'connection', (socket) ->
socket.on 'join room', (room) ->
socket.join room
pubsub.listen io.sockets, {
collection: 'events'
database: 'test'
host: 'localhost'
port: 27017
type: 'mongodb'
}
server.listen 3001
express = require 'express'
pubsub = require '../../lib/express-io-pubsub'
app = express()
app.configure () ->
app.use pubsub.middleware {
collection: 'events'
database: 'test'
host: 'localhost'
port: 27017
type: 'mongodb'
}
app.get '/', (req, res) ->
req.publish "lobby", "update", {msg: 'Hello World!'}
res.send "message sent"
app.listen 3002
Copyright (c) 2012 Bryant Williams <b.n.williams@gmail.com>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
FAQs
Express to Socket.io pubsub
We found that express-io-pubsub demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.
Research
/Security News
Ongoing npm supply chain attack spreads to DuckDB: multiple packages compromised with the same wallet-drainer malware.
Security News
The MCP Steering Committee has launched the official MCP Registry in preview, a central hub for discovering and publishing MCP servers.