Node.js Frameworks for a Server

In several projects, we constructed a server using plain Node.js with:

socket.on(‘eventName’, function(data) {})

With everything nested under:

on(‘connection’, function(socket){})

The following example attaches to a plain Node.JS http server listening on port 3000.

var server = require(‘http’).createServer();
var io = require(‘’)(server);
io.on(‘connection’, function(client){
client.on(‘event’, function(data){});
client.on(‘disconnect’, function(){});

This is not an experience I would recommend repeating. You end up with a large list of on blocks, with no structure.

HTTP and

The problem is exacerbated when the server also support calls over http. The code has two separate lists, one for http calls and one for calls. Even if the http calls are structured using a package like journey.


Express separates the calls from the standard route structure, so again it yields this split brain structure:

var app = require(‘express’)();
var server = require(‘http’).createServer(app);
var express = require(‘express’)

app.get(‘/’, function (req, res) {
res.send(‘Hello World!’)

var io = require(‘’)(server);
io.on(‘connection’, function(){ /* … */ });


However, later frameworks do better yielding a unified structure, and I would recommend using these.


Sails.js uses a uniform route structure for http and socket calls:

action: function(req, res) {


Testing whether the call is via a socket is done with:



Hapi in its plain form is like Express separating http from calls.

However, a plugin for hapi lets unify the route structure.


Choose the framework that yields a uniform route structure.

Written by

Open source, Mobile, Web, Cloud, Server - Independent Information Technology and Services Professional

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store