简体   繁体   中英

What utility of express.io VS express + socket.io?

I discover socket.io and chat exemple here : https://github.com/rauchg/chat-example/blob/master/index.js

They use directly require('express') AND require('socket.io') .

So what the differences, the advantages, to use : require('express.io') like here http://express-io.org/ ?

It's just to win one line? Seriously? or there is another layer with new tools?

I have been using express.io in my node app. I found that the principal advantage is that you can mix the normal express routes with socket routes.

Let me explain a real example:

In my app I have a nodejs REST API with an Angular clients. My clients need to show some real time notifications that were created by an administrator calling an express post request.

At the beginning I put a time interval in angular to consult all the notifications, running it every 5 seconds.
With a few clients it works perfect but when clients increased my server was overloaded. Each client was requesting notifications despite them not having new notifications. So I decided to start using socket.io to send real time notifications.

If my administrator saves a new notification, the server broadcasts the notification through the socket.
The problem here was that the administrator calls a normal POST request in express and I needed to broadcast using socket.io, so I integrate express.io and I can redirect normal express request to a socket.io method to do an emit.

var express = require('express.io');
var app = express();

app.http().io()

app.post('/notificacion', function(req, res){
//I save the notification on my db and then ...
req.io.route('enviar');
});

app.io.route('enviar', function(req) { 
    app.io.room('personas').broadcast('alertasControlador',req.io.request.data.notificacion);
});

I recently, today, looked at express.io and when i installed the node module npm reported:

Added 55 packages from 44 contributors and audited 2606 packages in 32.816s

Found 25 vulnerabilities (11 low, 5 moderate, 9 high)

run npm audit fix to fix them, or npm audit for details

npm audit fix fixed two of the low vulnerabilities.

When I removed express.io npm reported:

removed 57 packages and audited 2539 packages in 8.976s

found 0 vulnerabilities

So as much as I would like to use the really nice routing features, I don't feel this is appropriate for production until the dependencies are fixed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM