nes adds native WebSocket support to hapi-based application servers. Instead of treating the WebSocket connections as a separate platform with its own security and application context, nes builds on top of the existing hapi architecture to provide a flexible and organic extension.
Lead Maintainer - Eran Hammer
var Hapi = require('hapi');
var Nes = require('nes');
var server = new Hapi.Server();
server.connection();
server.register(Nes, function (err) {
server.route({
method: 'GET',
path: '/h',
config: {
id: 'hello',
handler: function (request, reply) {
return reply('world!');
}
}
});
server.start(function (err) { /* ... */ });
});
var Nes = require('nes');
var client = new Nes.Client('ws://localhost');
client.connect(function (err) {
client.request('hello', function (err, payload) { // Can also request '/h'
// payload -> 'world!'
});
});
});