node.js - Socket.io in a npm module -


i'm developping npm module should used in bigger application. module needs listen socket.io events, , i'm not sure on how include socket.io

i can see 2 solutions :

  • either include socket.io in module, , configure event listening. export main app can attach server

  • or, let server configure everything, let pass socket.io module when invokes module, , configure event listening on 1 given app.

the first solution has advantage not force main application include socket.io in dependency if don't need to.

the second solution force main app include socket.io in dependency, seems best solution approach.

what think ? should include socket.io in module, , let main app attach server, or should let main app give me access socket.io module?

i think common way have whoever invokes module inject server object. modules invoked like:

require('myapp')(server); 

then, in app, can attach socket.io server.

var io = require('socket.io')(server); 

also, can have optional options parameter can directly pass socket.io.

require('myapp')(server,options); 

there several advantages this. 0 configuration, not require user require socket.io, easy testing, configuration possible if desired.


Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

android - CollapsingToolbarLayout: position the ExpandedText programmatically -

Listeners to visualise results of load test in JMeter -