<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>integration &amp;mdash; Simple Engineering</title>
    <link>https://getsimple.works/tag:integration</link>
    <description></description>
    <pubDate>Tue, 28 Apr 2026 16:04:08 +0000</pubDate>
    <item>
      <title>Integration of redis in nodejs applications </title>
      <link>https://getsimple.works/integration-of-redis-in-nodejs-applications?pk_campaign=rss-feed</link>
      <description>&lt;![CDATA[The reactive aspect of nodejs applications is synonymous with the nodejs runtime itself. Even though the real-time aspect may be attributed to WebSocket implementation, the realtime reactive aspect of nodejs applications heavily rely on pub/sub mechanisms -- most of the time backed by datastore engines like redis.  This article explores how to integrate redis datastore into a nodejs application. &#xA;&#xA;In this article we will talk about: &#xA;&#xA;redis support with and without expressjs&#xA;redis support with and without WebSocket push mechanism&#xA;Alternatives to redis in nodejs world and beyond &#xA;&#xA;  Even though this blog post was designed to offer complementary materials to those who bought my Testing nodejs Applications book, the content can help any software developer to tuneup working environment. You use this link to buy the book.  Testing nodejs Applications Book Cover&#xA;&#xA;Show me the code&#xA;&#xA;The following code sample showcase how nodejs/redis integration can be achieved. It demonstrates that it is still possible to share sessions via a middleware between socket.io and expressjs.&#xA;&#xA;var app = express();&#xA;var server = Server(app);&#xA;var sio = require(&#34;socket.io&#34;)(server),&#xA;&#x9;redis = require(&#39;redis&#39;), &#xA;&#x9;rhost = process.env.REDISHOST,&#xA;&#x9;rport = process.env.REDISPORT,&#xA;&#x9;pub = redis.createClient(rport, rhost), &#xA;&#x9;sub = redis.createClient(rport, rhost);&#xA;&#xA;function middleware(req, res, next){&#xA; //session initialization thing&#xA; next();&#xA;}&#xA;&#xA;//socket.io/expressjs session sharing middleware&#xA;sio.use(function(socket, next){&#xA; &#x9;middleware(socket.request, socket.request.res, next);&#xA;});&#xA;&#xA;//express uses middleware for session management&#xA;app.use(middleware);&#xA;    &#xA;//somewhere&#xA;sio.sockets.on(&#34;connection&#34;, function(socket) {&#xA; &#xA; //socket.request.session &#xA; //Now it&#39;s available from socket.io sockets too! Win!&#xA; socket.on(&#39;message&#39;, (event) =  {&#xA;&#x9; var payload = JSON.parse(event.payload || event),&#xA;&#x9; &#x9;user = socket.handshake.user || false;&#xA;&#x9; &#xA;&#x9; //except when coming from pub  &#x9;&#x9;&#x9;&#xA;&#x9; pub.publish(payload.conversation, payload)); &#xA; });&#xA;&#xA; //redis listener&#xA; sub.on(&#39;message&#39;, function(channel, event) {&#xA;&#x9;var payload = JSON.parse(event.payload || event),&#xA;&#x9;&#x9;user = socket.handshake.user || false;&#xA;&#x9;sio.sockets.in(payload.conversation).emit(&#39;message&#39;, payload);&#xA; });&#xA;Example: excerpt source: StackOverflow&#xA;&#xA;What can possibly go wrong?&#xA;&#xA;When trying to figure out how to approach redis datastore integration into nodejs application for inter-process communication and real-time feature, the following points may be a challenge:&#xA;&#xA;How to decouple the WebSocket events from the redis specific (pub/sub) events. We should be able to decouple, but still provide an environment where interoperability is possible at any time. &#xA;How to make integration modular, testable, and overall friendly to the rest of the application ecosystem&#xA;&#xA;When testing this implementation, we should expect the additional challenge to emerge: &#xA;&#xA;The redis client instances (pub/sub) are created as soon as the library loads, and a redis server should be up and running by that time. The issue is when testing the application, there should be no server or any other system dependency hindering the application from being tested.  &#xA;getting rid of redis server with a drop-in-replacement, or stubs/mocks, is more of a dream than reality ~ hard but feasible.&#xA;&#xA;  There is additional information in mocking and stubbing redis data store in &#34;How to Mock redis datastore&#34; article. &#xA;&#xA;Conclusion &#xA;&#xA;In this article, we revisited how to enhance nodejs application with redis based pub/sub mechanism, critical to having a reactive real-time experience. The use of WebSocket and Pub/Sub powered by a key/value data store was especially the main focus of this article. There are additional complimentary materials in the &#34;Testing nodejs applications&#34; book. &#xA;&#xA;References&#xA;&#xA;Testing nodejs Applications book&#xA;Sharing session between expressjs and socket.io ~ StackOverflow Question&#xA;examples using redis with socket.io ~ StackOverflow Question&#xA;Using redis as PubSub over socket.io ~ StackOVerflow Question&#xA;socket.io - redis&#xA;redis pubsub library ~ Github Cloned Library&#xA;Building a Chat Server with node and redis - tests ~ Matthew Daly Blog&#xA;High Volume, low latency difficulties nodejs/pubsub/redis ~ StackOverflow Question&#xA;&#xA;#snippets #nodejs #integration #redis]]&gt;</description>
      <content:encoded><![CDATA[<p>The reactive aspect of <code>nodejs</code> applications is synonymous with the <code>nodejs</code> runtime itself. Even though the real-time aspect may be attributed to WebSocket implementation, the <strong><em>realtime reactive aspect</em></strong> of <code>nodejs</code> applications heavily rely on pub/sub mechanisms — most of the time backed by datastore engines like <code>redis</code>.  This article explores how to integrate <code>redis</code> datastore into a <code>nodejs</code> application.</p>

<p><strong><em>In this article we will talk about:</em></strong></p>
<ul><li><code>redis</code> support with and without <code>expressjs</code></li>
<li><code>redis</code> support with and without WebSocket push mechanism</li>
<li>Alternatives to <code>redis</code> in <code>nodejs</code> world and beyond</li></ul>

<blockquote><p>Even though this blog post was designed to offer complementary materials to those who bought my <strong><em><a href="https://bit.ly/2ZFJytb">Testing <code>nodejs</code> Applications book</a></em></strong>, the content can help any software developer to tuneup working environment. <strong><em><a href="https://bit.ly/2ZFJytb">You use this link to buy the book</a></em></strong>.  <a href="https://bit.ly/2ZFJytb"><img src="https://snap.as/a/42OS2vs.png" alt="Testing nodejs Applications Book Cover"/></a></p></blockquote>

<h2 id="show-me-the-code" id="show-me-the-code">Show me the code</h2>

<p>The following code sample showcase how <code>nodejs</code>/<code>redis</code> integration can be achieved. It demonstrates that it is still possible to share sessions via a middleware between <code>socket.io</code> and <code>expressjs</code>.</p>

<pre><code class="language-JavaScript">var app = express();
var server = Server(app);
var sio = require(&#34;socket.io&#34;)(server),
	redis = require(&#39;redis&#39;), 
	rhost = process.env.REDIS_HOST,
	rport = process.env.REDIS_PORT,
	pub = redis.createClient(rport, rhost), 
	sub = redis.createClient(rport, rhost);


function middleware(req, res, next){
 //session initialization thing
 next();
}

//socket.io/expressjs session sharing middleware
sio.use(function(socket, next){
 	middleware(socket.request, socket.request.res, next);
});

//express uses middleware for session management
app.use(middleware);
    
//somewhere
sio.sockets.on(&#34;connection&#34;, function(socket) {
 
 //socket.request.session 
 //Now it&#39;s available from `socket.io` sockets too! Win!
 socket.on(&#39;message&#39;, (event) =&gt; {
	 var payload = JSON.parse(event.payload || event),
	 	user = socket.handshake.user || false;
	 
	 //except when coming from pub  			
	 pub.publish(payload.conversation, payload)); 
 });

 //redis listener
 sub.on(&#39;message&#39;, function(channel, event) {
	var payload = JSON.parse(event.payload || event),
		user = socket.handshake.user || false;
	sio.sockets.in(payload.conversation).emit(&#39;message&#39;, payload);
 });
</code></pre>

<p><em><em>Example</em>: excerpt <a href="https://stackoverflow.com/a/25618636/132610">source: StackOverflow</a></em></p>

<h2 id="what-can-possibly-go-wrong" id="what-can-possibly-go-wrong">What can possibly go wrong?</h2>

<p>When trying to figure out how to approach <code>redis</code> datastore integration into <code>nodejs</code> application for inter-process communication and real-time feature, the following points may be a challenge:</p>
<ul><li>How to decouple the WebSocket events from the <code>redis</code> specific (<code>pub</code>/<code>sub</code>) events. We should be able to decouple, but still provide an environment where interoperability is possible at any time.</li>
<li>How to make integration modular, testable, and overall friendly to the rest of the application ecosystem</li></ul>

<p>When testing this implementation, we should expect the additional challenge to emerge:</p>
<ul><li>The <code>redis</code> client instances (<code>pub</code>/<code>sub</code>) are created as soon as the library loads, and a <code>redis</code> server should be up and running by that time. The issue is when testing the application, there should be no server or any other system dependency hindering the application from being tested.<br/></li>
<li>getting rid of <code>redis</code> server with a drop-in-replacement, or <code>stubs/mocks</code>, is more of a dream than reality ~ hard but feasible.</li></ul>

<blockquote><p>There is additional information in mocking and stubbing <code>redis</code> data store in <a href="./how-to-mock-redis-datastore.md">“How to Mock <code>redis</code> datastore”</a> article.</p></blockquote>

<h2 id="conclusion" id="conclusion">Conclusion</h2>

<p>In this article, we revisited how to enhance <code>nodejs</code> application with <code>redis</code> based pub/sub mechanism, critical to having a reactive real-time experience. The use of WebSocket and Pub/Sub powered by a key/value data store was especially the main focus of this article. There are additional complimentary materials in the <strong>“Testing <code>nodejs</code> applications”</strong> book.</p>

<h2 id="references" id="references">References</h2>
<ul><li><a href="https://bit.ly/2ZFJytb">Testing <code>nodejs</code> Applications book</a></li>
<li>Sharing session between <code>expressjs</code> and <code>socket.io</code> ~ <a href="https://stackoverflow.com/questions/25532692/how-to-share-sessions-with-socket-io-1-x-and-express-4-x">StackOverflow Question</a></li>
<li>examples using <code>redis</code> with <code>socket.io</code> ~ <a href="https://stackoverflow.com/questions/9267292/examples-in-using-redisstore-in-socket-io">StackOverflow Question</a></li>
<li>Using <code>redis</code> as <code>PubSub</code> over <code>socket.io</code> ~ <a href="https://stackoverflow.com/questions/32743754/using-redis-as-pubsub-over-socket-io">StackOVerflow Question</a></li>
<li><a href="https://github.com/socketio/socket.io-redis"><code>socket.io</code> – <code>redis</code></a></li>
<li><code>redis</code> <code>pubsub</code> library ~ <a href="https://github.com/murindwaz/redispubsub">Github Cloned Library</a></li>
<li>Building a Chat Server with node and <code>redis</code> – tests ~ <a href="https://matthewdaly.co.uk/blog/2014/12/31/building-a-chat-server-with-node-dot-js-and-redis/">Matthew Daly Blog</a></li>
<li>High Volume, low latency difficulties <code>nodejs</code>/<code>pubsub</code>/<code>redis</code> ~ <a href="https://stackoverflow.com/questions/10557826/node-js-socket-io-redis-pub-sub-high-volume-low-latency-difficulties">StackOverflow Question</a></li></ul>

<p><a href="https://getsimple.works/tag:snippets" class="hashtag"><span>#</span><span class="p-category">snippets</span></a> <a href="https://getsimple.works/tag:nodejs" class="hashtag"><span>#</span><span class="p-category">nodejs</span></a> <a href="https://getsimple.works/tag:integration" class="hashtag"><span>#</span><span class="p-category">integration</span></a> <a href="https://getsimple.works/tag:redis" class="hashtag"><span>#</span><span class="p-category">redis</span></a></p>
]]></content:encoded>
      <guid>https://getsimple.works/integration-of-redis-in-nodejs-applications</guid>
      <pubDate>Thu, 17 Jun 2021 04:46:06 +0000</pubDate>
    </item>
    <item>
      <title>Integration of WebSocket in nodejs application</title>
      <link>https://getsimple.works/integration-of-websocket-in-nodejs-application?pk_campaign=rss-feed</link>
      <description>&lt;![CDATA[The reactive aspect of nodejs applications is synonymous with the nodejs runtime itself. However, the real-time magic is attributed to the WebSocket addition. This article introduces how to integrate WebSocket support within an existing nodejs application.&#xA;&#xA;In this article we will talk about: &#xA;&#xA;WebSocket support with or without socket.io&#xA;WebSocket support with or without expressjs&#xA;Modularizations of WebSocket &#xA;&#xA;  Even though this blog post was designed to offer complementary materials to those who bought my Testing nodejs Applications book, the content can help any software developer to tuneup working environment. You use this link to buy the book.  Testing nodejs Applications Book Cover&#xA;&#xA;Show me the code&#xA;&#xA;Express routes use socket.io instance to deliver messages of a socket/socket.io enabled application looks like following: &#xA;&#xA;//module/socket.js - server or express app instance &#xA;module.exports = function(server){&#xA;  var io = socket();&#xA;  io = io.listen(server);&#xA;  io.on(&#39;connect&#39;, fn); &#xA;  io.on(&#39;disconnect&#39;,fn);&#xA;};&#xA;//OR&#xA;//module/socket.js &#xA;var io = require(&#39;socket.io&#39;);&#xA;module.exports = function(server){&#xA;  //server will be provided by the calling application&#xA;  //server = require(&#39;http&#39;).createServer(app);&#xA;  io = io.listen(server);&#xA;  return io;&#xA;};&#xA;&#xA;//module/routes.js - has all routes initializations&#xA;var route = require(&#39;express&#39;).Router();&#xA;module.exports = function(){&#xA;    route.all(&#39;&#39;,function(req, res, next){ &#xA;    &#x9;res.send(); &#xA;    &#x9;next();&#xA; });&#xA;};&#xA;&#xA;//in server.js &#xA;var app = require(&#39;express&#39;).express(),&#xA;  server = require(&#39;http&#39;).createServer(app),&#xA;  sio = require(&#39;module/socket.js&#39;)(server);&#xA;&#xA;//@link http://stackoverflow.com/a/25618636/132610&#xA;//Sharing session data between SocketIO and Express &#xA;sio.use(function(socket, next) {&#xA;    sessionMiddleware(socket.request, socket.request.res, next);&#xA;});&#xA;&#xA;//application app.js|server.js initialization, etc. &#xA;require(&#39;module/routes&#39;)(server); ;               &#xA;&#xA;What can possibly go wrong?&#xA;&#xA;When working in this kind of environment, we will find these two points to be of interest, if not challenging: &#xA;&#xA;For socket.io application to use same expressjs server instance, or sharing route instance with socket.io server&#xA;Sharing session between socket.io and expressjs application&#xA;&#xA;Conclusion &#xA;&#xA;In this article, we revisited how to add real-time experience to a nodejs application. The use of WebSocket and Pub/Sub powered by a key/value data store was especially the main focus of this article. There are additional complimentary materials in the &#34;Testing nodejs applications&#34; book.  &#xA;&#xA;References &#xA;&#xA;Testing nodejs Applications book&#xA;socket.io within concurrent processes ~ Tolleiv Nietsch Blog&#xA;nodejs, expressjs and socket.io application ~ DevelopIQ Blog&#xA;Modularize Your Chat App(or How to Write a nodejs Express App in More Than One File) ~ Philosophie Is Thinking Medium&#xA;Bacon.js + nodejs + MongoDB: Functional Reactive Programming on the Server ~ Carbon Five Blog&#xA;Modularizing socket.io with express 4 ~ StackOverflow Answer&#xA;&#xA;#snippets #nodejs #integration #WebSocket]]&gt;</description>
      <content:encoded><![CDATA[<p>The reactive aspect of <code>nodejs</code> applications is synonymous with the <code>nodejs</code> runtime itself. However, the real-time magic is attributed to the WebSocket addition. This article introduces how to integrate WebSocket support within an existing <code>nodejs</code> application.</p>

<p><strong><em>In this article we will talk about:</em></strong></p>
<ul><li>WebSocket support with or without <code>socket.io</code></li>
<li>WebSocket support with or without <code>expressjs</code></li>
<li>Modularizations of WebSocket</li></ul>

<blockquote><p>Even though this blog post was designed to offer complementary materials to those who bought my <strong><em><a href="https://bit.ly/2ZFJytb">Testing <code>nodejs</code> Applications book</a></em></strong>, the content can help any software developer to tuneup working environment. <strong><em><a href="https://bit.ly/2ZFJytb">You use this link to buy the book</a></em></strong>.  <a href="https://bit.ly/2ZFJytb"><img src="https://snap.as/a/42OS2vs.png" alt="Testing nodejs Applications Book Cover"/></a></p></blockquote>

<h2 id="show-me-the-code" id="show-me-the-code">Show me the code</h2>

<p>Express routes use <code>socket.io</code> instance to deliver messages of a <code>socket/socket.io</code> enabled application looks like following:</p>

<pre><code class="language-JavaScript">//module/socket.js - server or express app instance 
module.exports = function(server){
  var io = socket();
  io = io.listen(server);
  io.on(&#39;connect&#39;, fn); 
  io.on(&#39;disconnect&#39;,fn);
};
//OR
//module/socket.js 
var io = require(&#39;socket.io&#39;);
module.exports = function(server){
  //server will be provided by the calling application
  //server = require(&#39;http&#39;).createServer(app);
  io = io.listen(server);
  return io;
};

//module/routes.js - has all routes initializations
var route = require(&#39;express&#39;).Router();
module.exports = function(){
    route.all(&#39;&#39;,function(req, res, next){ 
    	res.send(); 
    	next();
 });
};

//in server.js 
var app = require(&#39;express&#39;).express(),
  server = require(&#39;http&#39;).createServer(app),
  sio = require(&#39;module/socket.js&#39;)(server);

//@link http://stackoverflow.com/a/25618636/132610
//Sharing session data between SocketIO and Express 
sio.use(function(socket, next) {
    sessionMiddleware(socket.request, socket.request.res, next);
});

//application app.js|server.js initialization, etc. 
require(&#39;module/routes&#39;)(server); ;               
</code></pre>

<h2 id="what-can-possibly-go-wrong" id="what-can-possibly-go-wrong">What can possibly go wrong?</h2>

<p>When working in this kind of environment, we will find these two points to be of interest, if not challenging:</p>
<ul><li>For <code>socket.io</code> application to use same <code>expressjs</code> server instance, or sharing route instance with <code>socket.io</code> server</li>
<li>Sharing session between <code>socket.io</code> and <code>expressjs</code> application</li></ul>

<h2 id="conclusion" id="conclusion">Conclusion</h2>

<p>In this article, we revisited how to add real-time experience to a <code>nodejs</code> application. The use of WebSocket and Pub/Sub powered by a key/value data store was especially the main focus of this article. There are additional complimentary materials in the <strong>“Testing <code>nodejs</code> applications”</strong> book.</p>

<h2 id="references" id="references">References</h2>
<ul><li><a href="https://bit.ly/2ZFJytb">Testing <code>nodejs</code> Applications book</a></li>
<li><code>socket.io</code> within concurrent processes ~ <a href="https://blog.tolleiv.de/2014/05/socket-dot-io-within-concurrent-processes/">Tolleiv Nietsch Blog</a></li>
<li><code>nodejs</code>, <code>expressjs</code> and <code>socket.io</code> application ~ <a href="https://developeriq.in/articles/2015/feb/03/nodeexpressjs-and-socketio-application/">DevelopIQ Blog</a></li>
<li>Modularize Your Chat App(or How to Write a <code>nodejs</code> Express App in More Than One File) ~ <a href="https://medium.com/philosophie-is-thinking/modularize-your-chat-app-or-how-to-write-a-node-js-express-app-in-more-than-one-file-bfae2d6b69df#.hfb4r6z3i">Philosophie Is Thinking Medium</a></li>
<li><code>Bacon.js</code> + <code>nodejs</code> + <code>MongoDB</code>: Functional Reactive Programming on the Server ~ <a href="https://blog.carbonfive.com/2014/09/23/bacon-js-node-js-mongodb-functional-reactive-programming-on-the-server/">Carbon Five Blog</a></li>
<li>Modularizing <code>socket.io</code> with express 4 ~ <a href="https://stackoverflow.com/a/29697470/132610">StackOverflow Answer</a></li></ul>

<p><a href="https://getsimple.works/tag:snippets" class="hashtag"><span>#</span><span class="p-category">snippets</span></a> <a href="https://getsimple.works/tag:nodejs" class="hashtag"><span>#</span><span class="p-category">nodejs</span></a> <a href="https://getsimple.works/tag:integration" class="hashtag"><span>#</span><span class="p-category">integration</span></a> <a href="https://getsimple.works/tag:WebSocket" class="hashtag"><span>#</span><span class="p-category">WebSocket</span></a></p>
]]></content:encoded>
      <guid>https://getsimple.works/integration-of-websocket-in-nodejs-application</guid>
      <pubDate>Thu, 17 Jun 2021 04:43:53 +0000</pubDate>
    </item>
  </channel>
</rss>